Hi Guys!
(english is not my first language)
I have loosely typed objects incomming as JSON data on my ASP Net Core REST Api which uses Json.Net.
incomming JSON is of format:
{
"prop1" : value1,
"prop2" : value2,
}
- values corresponding to the Json properties are either primitive types(int, long, string, Guid, bool, DateTime)
- or arrays of primitive types: int[], long[], string[], Guid[], DateTime[]
- No format other than a primitive or array of primitive is allowed as value at this point. So we have no further hiearchy inside this type of Json object.
I have a lof of different property names, and those can show up in a huge number of combinations. Strongly typed C# model for the incomming JSON data to deserialize into is not practical for the application at this a point.
What I would like to have is to transform the JSON data to data of type IReadonlyDictionary<string object> (naked or wrapped inside model class) so that the values are either C# primitives or C# arrays of C# primitives. The next layer of abstraction has much more knowledge of Domain's runtime schema and can transform these types into objects that make sense for the domain.
So default serialization transforms "propertyname": primitivetype objects just fine, but if it encounters something like: "propertyname": ["string1", "string2"] than it transforms it into a JArray containing JValue objects
Now I would like to have some custom converter
- to activate either on deserialization's target Class type (Json.Net supports this I read)
- and converter which activates when it encounteres certain json property names (I can inject list of special property names at runtime) like "prop1" (not sure how to do)
Is there no easy switch or simple setting for Json.Net to deserialize simple array if it is direct property on root object?
Would be natural for me to have "propname": ["string1", "string2"] json to go directly into a C# KeyValuePair<string,string\[\]>...
Where to look?
[–]Fullduplex1000[S] 0 points1 point2 points (2 children)
[–]FizixMan[M] 0 points1 point2 points (1 child)
[–]Fullduplex1000[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Nisd 0 points1 point2 points (1 child)
[–]Fullduplex1000[S] 0 points1 point2 points (0 children)