Im trying to parse my class to Json, but i have some problemas to do it like i want.
{
"bool": {
"must": [
{
"Term": {
"number": 5
}
},
{
"Match": {
"name": "xxx"
}
}
]
}
}
my class is
public class BaseLeafQuery
{
public BaseFilterType Bool { get; set; }
}
public class BaseFilterType
{
[JsonProperty(PropertyName = "must", NullValueHandling = NullValueHandling.Ignore)]
public List<BaseTypeQuery> Must { get; set; }
}
public class BaseTypeQuery {
[JsonProperty(PropertyName = "term", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, object> Term { get; set; }
[JsonProperty(PropertyName = "match", NullValueHandling = NullValueHandling.Ignore)]
public Dictionary<string, object> Match { get; set; }
}
But when i convert the json becomes it
{
"bool": {
"must": [
{
"Term": {
"number": 5
},
"Match": {
"name": "xxx"
}
}
]
}
}
Every class inside the "MUST" class must be beetween {}
Example:
BaseTypeQuery baseTypeQuery = new BaseTypeQuery();
baseTypeQuery.Term = new Dictionary<string, object>() { { "Id", 5 } };
baseTypeQuery.Match = new Dictionary<string, object>() { { "Email", "xxx" } };
BaseLeafQuery leafQuery = new BaseLeafQuery();
leafQuery.Bool = new BaseFilterType();
leafQuery.Bool.Must = new List<BaseTypeQuery>();
leafQuery.Bool.Must.Add(baseTypeQuery);
var a = JsonConvert.SerializeObject(leafQuery);
The result of A is {"bool":{"must":[{"term":{"Id":5},"match":{"Email":"xxx"}}]}} but should bu {"bool":{"must":[{"term":{"Id":5}},{"match":{"Email":"xxx"}}]}}