[rabbitmq-discuss] Sending messages with abstract types as properties

Tim Watson tim at rabbitmq.com
Fri Oct 26 01:57:31 BST 2012


On 25 Oct 2012, at 22:36, kayslay wrote:

> I have a message that I'm sending and one of it's properties is an abstract type.  When I send this message I get an exception on the receiver from the json serializer:
> How am I able to receive a message that has an interface or abstract type property, here MyPayload is an abstract class?
> Thanks
> Exception:
> Newtonsoft.Json.JsonSerializationException: Could not create an instance of type
>  MyNamespace.Payloads.MyPayload. Type
>  is an interface or abstract class and cannot be instantated. Path 'Payload.Id',
>  line 1, position 17.

This is really a question for however supplies the Newtonsoft.Json package. I know that with some serialisation frameworks this just works transparently, because the framework 'bakes' the concrete classname into the representation at runtime, but gives you back a reference to the type you're expecting. Some frameworks allow you do write serialize/deserialize hooks to do this as well. Generics add a bit more complexity.

Either way, this hasn't really got anything to do with RabbitMQ so I'd suggest contacting the author on github, assuming it is https://github.com/mikehadlow/EasyNetQ that we're talking about.


More information about the rabbitmq-discuss mailing list