Profilep=mapper.readValue("{\"id\": 42}",Profile.class);// p.id() is "42", with no errorimportcom.fasterxml.jackson.databind.cfg.CoercionAction;importcom.fasterxml.jackson.databind.cfg.CoercionInputShape;importcom.fasterxml.jackson.databind.type.LogicalType;ObjectMapperstrict=newObjectMapper().registerModule(newJdk8Module());strict.coercionConfigFor(LogicalType.Textual).setCoercion(CoercionInputShape.Integer,CoercionAction.Fail).setCoercion(CoercionInputShape.Float,CoercionAction.Fail);
Null, absent, and present
Evolving schemas safely
Add new fields as optional, with a defined default.
Never change a field's type in place. Add a new field and deprecate the old one.
Never reuse a removed field's name for different data.
Treat enum changes with care. Configure an unknown-value fallback (for example READ_UNKNOWN_ENUM_VALUES_USING_DEFAULT_VALUE with a default) so old clients survive new symbols.
Top comments (0)