I want to serialise an object into JSON send it across the wire via rabbitmq and then deserialize it.
I have the following object that I am serialising:
lead = Lead.new
lead.company = 'some company'
operation = proc{ AMQP::Exchange.default.publish(
lead.to_json,
:routing_key => header.reply_to,
:correlation_id => header.correlation_id
)}
On the other side, I am trying to descerialise the object like this:
callback_queue.subscribe do |header, body|
puts "received #{body.inspect}"
lead = ActiveSupport::JSON.decode body
puts lead.company #NoMethodError: undefined method `company' for #<Array:0x6fe03f3b>
The json is strangely an array of 3 hashes and looks like this.
[{\"created_at\":null,\"email\":\"dagda1@scotalt.net\",\"id\":null,\"lead_id\":null,\"updated_at\":null},{\"created_at\":null,\"email\":\"paul.cowan@continuity2.com\",\"id\":null,\"lead_id\":null,\"updated_at\":null}]"
Can anyone see anything I am doing wrong?