c# - Rebus RabbitMQ Object serialization -
how come when send message rabbitmq through rebus adding object data below, $type.
{"$type":"threesquared.vtgpam.objects.wagon, threesquared.vtgpam.objects","wagonid":"a98a06ab-33b9-4a11-9de2-df0b8787b713","wamosid":12324,"description":"test","yearbuilt":1982,"token":"3cce443c-249f-4fd2-9882-5830fb308b6b"}
we have client using java rabbitmq library no rebus. approach believe send json without type declarations. therefore doesn't work when try , read in simple json object. how can make work doesn't define $type in message?
it's because rebus default uses newtonsoft json.net typenamehandling.all
, means $type
field included in every serialized object containing full .net type name of type serialized.
the benefit can serialize anything, though may contain instances referenced (possibly abstract) supertypes, , interfaces.
e.g. command message type
public class processfile { public processfile(string filepath, ienumerable<ifileprocessingtask> tasks) { filepath = filepath; tasks = tasks; } public string filepath { get; } public ireadonlycollection<ifileprocessingtask> tasks { get; } }
could contain arbitrary implementations of ifileprocessingtask
, e.g.
public class gzipfileprocessingtask : ifileprocessingtask { // ... }
as long recipient can find type looking via value of $type
field.
if want process type of message on platform, can make ignore $type
field of every object. may easy/hard/impossible, depending on how flexible json serializer is.
another option replace rebus' serializer own implementation doing this
configure.with(...) .(...) .serialization(s => s.usecustomjsonserialization()) .start();
where usecustomjsonserialization
extension method implement this:
public static class rebusconfigex { public static void usecustomjsonserialization(this standardconfigurer<iserializer> configurer) { configurer.register(c => new yourcustomjsonserializer()); } }
and there left create class yourcustomjsonserializer
implementation of iserializer
.
wiki
Comments
Post a Comment