'Which `JsonInclude.Include` value does Jackson use if it has not been configured explicitly?
The documentation on JsonInclude.Include.USE_DEFAULTS
reads:
Pseudo-value used to indicate that the higher-level defaults make sense, to avoid overriding inclusion value. For example, if returned for a property this would use defaults for the class that contains property, if any defined; and if none defined for that, then global serialization inclusion details.
So what does this global inclusion value default to?
Also, can this default be relied on, or is it something that is frequently changed by other frameworks, e. g. Spring, during confiduration?
Solution 1:[1]
Copying the text of your first question from the title of the post:
Which JsonInclude.Include value does Jackson use if it has not been configured explicitly?
It uses the ObjectMapper
configuration settings that are equals to JsonInclude.Include.USE_DEFAULTS
for content and value fields (map entries and classes) :
ObjectMapper objectMapper = new ObjectMapper();
Value value = objectMapper.getSerializationConfig().getDefaultPropertyInclusion();
System.out.println(value); //<-- JsonInclude.Value(value=USE_DEFAULTS,content=USE_DEFAULTS)
Your second question:
Also, can this default be relied on, or is it something that is frequently changed by other frameworks, e. g. Spring, during confiduration?
For Spring framework the initial configuration starts with the same values previously said, so unless you explicitely set it to new values or create a custom ObjectMapper
you can rely on it.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | dariosicily |