Thank you in advance. I am really stuck on this one, but practicing. Thank you in advance for any help.
I am able to successfully build this Json object in my code, but de-serializing it with the same Dictionary I used to build it, is not working because the string type defined is anonymous and I cannot access specifically the sub items (contains, equals, startsWith).
I have my json being built successfully but again, does not work when deserializing it.
{
"shortDescription": {
"contains": false,
"equals": false,
"startsWith": true,
"value": "some text"
},
"description": {
"contains": true,
"equals": false,
"startsWith": false,
"value": "some more text"
},
"createdAfter": {
"contains": false,
"equals": false,
"startsWith": false,
"value": "2021-08-17"
},
"notes": "Something bad happened",
"group": "some group",
"assigned": "to me"
}
These objects like shortDescription may not even exist depending on user selection which I why I built an anonymous type Dictionary using "String" public Dictionary<string, filter_properties> properties { get; set; } I can apply this format to any object that needs these properties.
public class filter_keys
{
public string notes { get; set; }
public string group { get; set; }
public string assigned { get; set; }
public Dictionary<string, filter_properties> properties { get; set; }
}
public class filter_properties
{
public bool contains { get; set; }
public bool equals { get; set; }
public bool startsWith { get; set; }
public string value { get; set; }
}
I would really appreciate some help to figure out how to set a simple property only for this description and shortDescription fields, not just to serialize the data but also to de-serialize the data, so I can check if these objects even exist in the json.
When I am setting the json I use
Dictionary<string, filter_properties> keys = new Dictionary<string, filter_properties>();
keys.Add("anonymous", new filter_properties { value="can't find it" });
and/or
keys.Add("shortDescription", new filter_properties {
contains = true,
value = "blah blah blah"
});
shortDescriptionthat may not even exist or that the possible set of properties is not known in advance and is unlimited?is not working? Also can you share the code of serialization and deserialization?propertiesin your POCO class, but in the json,shortDescription,description, andcreatedAfterare all in the root, not under apropertiesnode. What happens if you reconstruct your json to put those three under apropertiesnode?notesandgroup) along with a variable set of properties whose values have a fixed schema, herefilter_properties, you can use[JsonTypedExtensionData] public Dictionary<string, filter_properties> properties { get; set; }where[JsonTypedExtensionData]and its associatedTypedExtensionDataConverter<filter_keys>come from How to deserialize a child object with dynamic (numeric) key names?.