I would like to send Json to the server, and we do that with Newtonsoft's Json.NET1. The json may contain type information ("$type" = ...). This type info may point to an unknown type. Said object would typically be contained in a property of type object.
What I would like to do:
- Convert the part of the unknown type to a JObject
- Preserve somehow the type information, so I can send the same json back to the client at a later point as it was passed to the server.
What I've tried so far
By replacing the
SerializationBinder
on theJsonSerializer
, I can force Json.NET to deserialize the json contained into aJObject
. This is almost what I would like to have, alas the $type property is lost.In the binder returning a type that points to an object that would work in harmony with a custom
JsonConverter
which would gobble up the offending object such that upon write it would faithfully recreate the json as it was encountered. However, when you hit the $type info, no converters will be called anymore, apparently we are then in a different branch of the json.NET codeOne can handle a serialization error, try to read from the reader the offending part, then one could create a JOBject manually and annotate the type information.
1) More specific - the built of it that is contained in the RavenDB.Abstractions, but hopefully they have not diverged too much.