There is a minor bug with simple-json poco deserialization when a JSON key can either hold an object or an array. For an instance of this, see these JSON-RPC specifications regarding the "params" key of their JSON Request object. The specifications state that:
[when passing] by-position: params MUST be an Array...
[when passing] by-name: params MUST be an Object...
For this type of JSON schema, I define my poco data class like this:
class JsonMessage {
public string method { get; set; }
public object @params { get; set; }
}
I expected the @params property of my JsonMessage instance to contain either a JsonObject or a JsonArray, depending on whichever one was given in the JSON. Simple-json performed as expected in the case where a key/value object was present in the JSON for the "params" key.
However, when the JSON "params" key had an array, my @params property is null. The problem happens during deserialization when Line 1457 of SimpleJson.cs is executed because the list variable is null even though value still contains something useful to me (a JsonArray instance).
So, my simple way of solving this was to change this line to say obj = list ?? value;.
There is a minor bug with simple-json poco deserialization when a JSON key can either hold an object or an array. For an instance of this, see these JSON-RPC specifications regarding the "params" key of their JSON Request object. The specifications state that:
For this type of JSON schema, I define my poco data class like this:
I expected the
@params
property of myJsonMessage
instance to contain either aJsonObject
or aJsonArray
, depending on whichever one was given in the JSON. Simple-json performed as expected in the case where a key/value object was present in the JSON for the"params"
key.However, when the JSON
"params"
key had an array, my@params
property isnull
. The problem happens during deserialization when Line 1457 of SimpleJson.cs is executed because thelist
variable isnull
even thoughvalue
still contains something useful to me (aJsonArray
instance).So, my simple way of solving this was to change this line to say
obj = list ?? value;
.