Reputation: 4491
I have an API hosted/written in DropWizard. It consumes JSON and works well
@POST
public void somePost(SomeObject object)
Where SomeObject
is a pojo. Jackson deserialises JSON into the object without a problem.
To future proof the "calling code" that uses this API I started to add some properties that are not yet in SomeObject
. However (presumably Jackson) now throws an "error parsing json" error.
I would like to relax the rules a bit so that Jackson is a bit more tolerant about fields that it doesn't recognise in the incoming JSON (GSON does that by default). I tried @JsonIgnoreProperties
class level annotation but no luck.
Thanks in advance.
Upvotes: 2
Views: 294
Reputation: 116572
Another option is to just globally allow any and all unknown properties by disabling DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
. It may be dangerous in just ignoring everything that does not map, but for "Open Content" style usage it works great.
Upvotes: 0
Reputation: 421
You said that you tried @JsonIgnoreProperties. Have you tried it like this?
@JsonIgnoreProperties(ignoreUnknown = true)
Tested above one and it should work.
Upvotes: 4