I am attempting to migrate the implementation details of some JSON databinding code to use the Java EE 8 JSON-B APIs instead of Jackson.
In order to match the default behavior of Jackson, I want to reject any attempts to deserialize a JSON payload into a POJO when the JSON payload contains unrecognized attributes.
For example, if I have the following JSON data:
{
"name": "Bob",
"extraProp": "Something"
}
And I have the following Java Object that models this data as:
public class Thing {
public String name;
// no mention of "extraProp"
}
How would I reject attempts to bind the above JSON data into the above POJO?
If I try the following, the Thing
object gets created without error (here I want an error to occur):
Jsonb jsonb = JsonbProvider.provider()
.create()
.build();
Thing t = jsonb.fromJson("{\"name\":\"Bob\",\"extraProp\":\"Something\"}", Thing .class);