-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Json serialization issure, not compatible types #391
Comments
Newtonsoft encodes the type in a special $type field, and this is used for deserialisation to the correct type. This is as intended, as otherwise during deserialisation the consumer would have to take a guess at the type of the request and could easily get this wrong. Trying to match the props does not give the required guarantee that the type is correct. You will likely need to share your OrderCreated class in a common library that both consumer and producer can use. |
Also, if you want to customise serialisation/deserialisation (sounds like you might need to), you can use a JsonConverter |
Hey, thank you for responding, @alexdawes your solution is what i ended up doing, but i with this project i was trying to follow these guys https://github.com/devmentors, and they are keeping their models, events and commands in projects that require it not in a common 'global' project, for exmaple https://github.com/devmentors/DNC-DShop.Services.Orders/tree/master/src/DShop.Services.Orders any idea how they bypassed it? |
Please check projects above, take OrderCreated for an exmaple, Notifications app subscribes to OrderCreated which is an Event class owned by Notifications app, but the event itself is emitted by Orders app, two different classes, somehow are serialized properly |
Interesting! The Notifications app uses a This is then used within a custom RabbitMQ However, I've no idea how the app is avoiding the Newtonsoft serialisation issue that you are seeing. It could be that I am simply wrong, and either it is possible to override the JsonSerialiserSettings being used by Rabbit, or else the Probably worth pointing out that I am not a RawRabbit expert - your ticket interested me and I thought I could help out, but its possible my understanding of things is simply wrong. For what its worth as well, the setup used by DShop seems a little flimsy and liable to fall over if types change or are moved between namespaces etc. I therefore would still recommend sharing commands/events via a common lib where possible, even if you can work it out, as at least then you can publish new versions of the common lib for clients to use if there are breaking API changes. I'll try to take a more in depth look at things later, as I'm keen to understand whats being done here. |
Ahh I may have worked out where I was wrong. RawRabbit uses This means that the My guess here is that DShop is using types where this is not the case, and so $type is never used and hence deserialisation doesnt find it and complain. As mentioned above, looks like routing is manually handled by the use of attributes. @cocowalla In your example above were your |
I have ran into the same issue but have set However... with Request/Respond the deserialization is reading the type from the Headers.message_type and using |
Interesting - @simon-davis did you get anywhere with this? From a quick glance in the source code, I cant actually see any use of |
Hey, have you encoutered any problems with newtonsoft’s serializer? Let’s say i have an event SomeEvent:IEvent in two+ of my microserivces, whenever i’m listening for this event with rabbitmq i get the message but because of the object’s namespace Newtonsoft cant parse it properly and is throwing exceptions
for example
Type specified in JSON ‘Orders.OrderCreated’ is not compatible with ‘Notifications.OrderCreated’ i thought it would just try to match the props? Can you please point me in the right direction?
Using version 1.10.4
Thanks
The text was updated successfully, but these errors were encountered: