2

How can I mark as ignored some properties using json schema or jsonschema2pojo plugin? Sometimes I do receive these properties, sometimes I do not.

Here is the exception I am having:

com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "warnings" (class com.xyz.music.napster.v2.metadata.MetaVO), not marked as ignorable (2 known properties: "returnedCount", "totalCount"]) at [Source: okhttp3.ResponseBody$BomAwareReader@49f94818; line: 1, column: 15846] (through reference chain: com.xyz.music.napster.v2.metadata.PlaylistsResponseVO["meta"]->com.xyz.music.napster.v2.metadata.MetaVO["warnings"])

Here is my schema for MetaVO class

{
  "properties": {
    "returnedCount": {
      "type": "integer"
    },
    "totalCount": {
      "type": "integer"
    }
  },
  "type": "object"
}

For the moment I have found if I set the following annotation on MetaVO class

@JsonIgnoreProperties(ignoreUnknown = true)

my problem is solved.

However these classes are auto-generated by the plugin (and according to our project specs they have to stay so).

Is it possible to do anything like this from json schema or jsonschema2pojo plugin?

Flowryn
  • 1,437
  • 1
  • 16
  • 32

2 Answers2

0

I managed to solve the issue by switching from jackson-converter to gson-converter.

Flowryn
  • 1,437
  • 1
  • 16
  • 32
0

In jsonschema2pojo case these properties can be deleted from json or jsonschema used for generating pojos.

When they are retrieved in json they will be deserialized and added to pojo's Map<String, Object> additionalProperties field. additionalProperties field is created by default. Make sure it is not disabledin schema "additionalProperties": false

Tihomir
  • 124
  • 1
  • 11