Closed cowtowncoder closed 1 year ago
Ok, to configure new behavior -- absent (missing) Optional
s becoming Java null
s you need to configure module, register it. So:
Jdk8Module module = new Jdk8Module()
.configureReadAbsentAsNull(true);
final ObjectMapper mapper = JsonMapper.builder()
.addModule(module)
.build();
This will be in 2.14.0 release.
So, for case like:
with JSON like
current handling would assign
Optional.empty()
tovalue
. But other reference types, likeAtomicReference
will instead assignnull
. This is to differentiate case of reading JSON like:in which value for all reference types becomes "empty" value (new AtomicReference<>, Optional.empty()).
This should be fixed for 2.14. But since this is a behavioral change it is also necessary to add configurability to allow old behavior, at least for 2.x. And to maximize backwards compatibility we probably have to default to old and (IMO) sub-optimal handling.