I am trying to analyze the filter parameters sent by the KendoUI network to my web service, and I have some problems that convince Jackson to parse this JSON. As far as I know, I can control the format of the parameters that Kendo sends, but I do not know how I would marshal the parameters in a more convenient format so that they remain unchanged at the moment.
I intend to convert these parameters into an SQL query for an Oracle database.
JSON example:
{ "filters": [ { "field": "Name", "operator": "contains", "value": "John" }, { "filters": [ { "field": "Age", "operator": "gt", "value": 20 }, { "field": "Age", "operator": "lt", "value": 85 } ], "logic", "and" }, { "field": "Address", "operator": "doesnotcontain", "value": "street" } ], "logic": "or" }
Filters Java
public class Filters { private List<Filter> filters; private String logic;
Filter.java
public class Filter { private String field; private String operator; private String value;
Unit test
public class KendoGridFilterTest { private ObjectMapper mapper; @Before public void before() { mapper = new ObjectMapper(); } @Test public void jsonParseTest() { final String json = "{\"filters\":[{\"field\":\"Name\",\"operator\":\"contains\",\"value\":\"John\"},{filters: [{\"field\":\"Age\",\"operator\": \"eq\",\"value\": 85},{\"field\": \"Age\",\"operator\": \"eq\",\"value\": 85}]\"logic\", \"and\",},{\"field\": \"Address\",\"operator\": \"doesnotcontain\",\"value\": \"street\"}],\"logic\":\"or\"}"; Filters filters = mapper.readValue(json, Filters.class); assertTrue(json.equals(filters.writeValueAsString(filters); } }
Mistakes
com.fasterxml.jackson.databind.UnrecognizedPropertyException: Unrecognized field
'logic' (com.example.Filter) not market as ignorable (3 known properties
"value", "field", "operator")
at [Source: java.io.StringReader@3bb2b8 ; line: 1, column 76] (through reference
chain: com.example.Filters ["filters"] -> com.example.Filter ["logic"]
I also tried adding @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@id") to the Filters class and getting the same errors.