I have two ObjectMapper instances of Jackson. (Using v2.8.3)
The first one is instantiated as follows:
ObjectMapper objectMapper = new ObjectMapper();
The other one is autowired from the Spring Boot context via @Autowired
.
Both have the same visibility configurations like this:
But they produce different serializations for the same object. The differences I realized are as follows:
- Order of the serialized fields
- Serialization of protected transient fields. (The autowired instance does not serialize them at all.)
- Case differences in the serialized fields i.e. the former generates "monitoringUserID" while the latter "MonitoringUserID".
What I want is that the autowired mapper would also serialize the protected transient fields.
I'd also be glad if you tell me the reasons on the other differences in both serializations.
A simplified version of an example class being serialized:
public class ClauseType implements Serializable {
protected transient List<ClauseTypeNoteItem> noteItems;
public ClauseType() {
}
public List<ClauseTypeNoteItem> getNoteItems() {
...
}
public void setNoteItems(List<ClauseTypeNoteItem> value) {
...
}
}
Complete ClauseType class: https://pastebin.com/m3h1hesn
Complete ClauseTypeNoteItem class: https://pastebin.com/dmphNV4e
Edit:
I realized that both instances had difference mapper features. According to the docs, after enabling the DEFAULT_VIEW_INCLUSION
featured of the autowired instance, they had the same mapper features represented as 1068991. However the differences are still there. I also realized that the autowired mapper has two registered modules: org.springframework.boot.jackson.JsonComponentModule
and com.fasterxml.jackson.datatype.joda.JodaModule
. I'm not sure whether the second module has an effect on the results I'm getting.
Thanks in advance.