I have a class like so:
[JsonObject]
public class Condition
{
[JsonProperty(PropertyName = "_id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "expressions", NullValueHandling = NullValueHandling.Ignore)]
public IEnumerable<Expression> Expressions { get; set; }
[JsonProperty(PropertyName = "logical_operation")]
[JsonConverter(typeof(StringEnumConverter))]
public LogicOp? LogicalOperation { get; set; }
[JsonProperty(PropertyName = "_type")]
[JsonConverter(typeof(AssessmentExpressionTypeConverter))]
public ExpressionType Type { get; set; }
}
However, when the Expressions
property is null, and I serialize the object like so:
var serialized = JsonConvert.SerializeObject(condition, Formatting.Indented);
... the text of the Json string has the line:
"expressions": null
My understanding is that this should not happen. What am I doing wrong?