In my project, I have a TypeScript component that retrieves JSON data, and I need to parse this JSON in C# to work with the objects. However, due to the presence of:
- multiple type fields
- recursion
it's becoming challenging to understand how the deserialization process should be implemented. I am aware that I need to use a JsonConverter for handling multiple type fields, but I'm unsure how to handle recursion in conjunction with multiple type fields.
Below is the TypeScript code responsible for generating the JSON:
export interface FilterDescriptor {
field ? : string | Function;
operator: string | Function;
value ? : any;
ignoreCase ? : boolean;
}
export interface CompositeFilterDescriptor {
logic: 'or' | 'and';
filters: Array < FilterDescriptor | CompositeFilterDescriptor > ;
}
export declare
const isCompositeFilterDescriptor: (source: FilterDescriptor | CompositeFilterDescriptor) => source is CompositeFilterDescriptor;
Here are some examples of the generated JSON:
With recursion:
{
"logic": "and",
"filters": [
{
"field": "type.group",
"logic": "and",
"filters": [
{
"field": "type.group",
"operator": "neq",
"value": 2
},
{
"field": "type.group",
"operator": "neq",
"value": 5
}
]
}
]}
Without recursion:
{
"logic": "and",
"filters": [
{
"field": "type.group",
"operator": "eq",
"value": 2
}
]}
This JSON is generated using Kendo UI for Angular from Telerik's "CompositeFilterDescriptor."
Thank you.