-
Notifications
You must be signed in to change notification settings - Fork 39
Open
Description
I'm confused with setup in "Usage section":
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.registerModule(new JsonNullableModule());
Please take a look on the following snippet ( val=null is passed in JSON and in Map):
record A (JsonNullable<BigDecimal> val) {}
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JsonNullableModule());
A a1 = objectMapper.readValue("{ \"val\" : null }", A.class);
System.out.println(a1);
HashMap hashMap = new HashMap();
hashMap.put("val", null);
A a2 = objectMapper.convertValue(hashMap, A.class);
System.out.println(a2);
Output is consistent
A[val=JsonNullable[null]]
A[val=JsonNullable[null]]
But with setup
ObjectMapper objectMapper = new ObjectMapper().registerModule(new JsonNullableModule())
.setSerializationInclusion(JsonInclude.Include.NON_NULL);
Output is not consistent
A[val=JsonNullable[null]]
A[val=JsonNullable.undefined]
Well, time for questions:
- I do not understand why you propose in "Usage" section setup
.setSerializationInclusion(JsonInclude.Include.NON_NULL). It looks useless. - I do not understand how serialization setup may affect deserialization (
objectMapper.convertValueis deserialization)
andrej-urvantsev
Metadata
Metadata
Assignees
Labels
No labels