I'm getting some problems trying to deserialize a "dynamic" JSON structure in my application.
I'm receiving a json object which have a field, packages
, that can be valorized as an array of strings or as an array of "objects". So, in some situation I have something like this:
"packages" : [ "Test", "Var" ]
and somethimes I have:
"packages" : [ {
"id" : "9",
"name" : "Test"
},
{
"id" : "19",
"name" : "Opt"
}]
In my domain class I tried to define the packages field this way:
public List<object> packages { get; set; }
But this seems to work only when I'm deserializing array of strings. When I'm getting objects, instead, the packages
field in my class is valorized as null
.
How can I solve this issue? Can I avoid deserialization just for the packages
fileld and get the value as a simple string?
NOTE: I also tried to define the field like this:
public String packages { get; set; }
but I'm getting an exception...