Friday, 6 September 2013

JSON.NET Deserialization Issue

JSON.NET Deserialization Issue

I'm having trouble deserializing certain data with JSON.NET. The following
string, although serialized via JSON.NET, will not deserialize correctly.
{"ParentClause":null,"FilterClauseType":2,"FilterClauses":[
{"FilterClauseType":1,"FilterClauses":[],"ComparisonType":2,"FieldStaticName":"ContentType","Value":"Hidden","FieldValueType":2},
{"FilterClauseType":1,"FilterClauses":[],"ComparisonType":1,"FieldStaticName":"ContentType","Value":"Document","FieldValueType":2}],
"ComparisonType":null,"FieldStaticName":null,"Value":null,"FieldValueType":null}
Doing JsonConvert.DeserializeObject() skips the elements of the
FilterClauses array, even though they're clearly present. This occurs
whether I use the generic or non-generic overload of the method.
Is this a bug, or is there some way to fix this? I tried implementing a
custom JsonConverter, but the JReader passed into that is throwing
exceptions.
For reference, this is the class definition:
class FilterClause
{
public FilterClause ParentClause {get; set;}
public FilterClauseType FilterClauseType {get; set;}
public IList<FilterClause> FilterClauses {get; set;}
public ComparisonType? ComparisonType {get; set;}
public String FieldStaticName {get; set;}
public String Value {get; set;}
public FieldValueType? FieldValueType {get; set;}
public FilterClause()
{
FilterClauses = ImmutableList.Create<FilterClause>();
}
}

No comments:

Post a Comment