Feature: Allow using Arbitrary Constructor or Factory Method for instantiation
(see Jira entry JACKSON-244 for details)
Prior to 1.5, there were already some ways to define what kinds of methods, fields and creators (constructors and static factory methods) can be auto-detected. For example:
You could enable/disable auto-detection for specific types (getters, setters, fields, creators) via SerializationConfig and DeserializationConfig.
You can similarly enable/disable auto-detection using @JsonAutoDetect
However: this only allows enabling/disabling auto-detection, but not changing what visibility level is required. Existing settings were (and are) such that:
For getters, "is-getters", creators and fields, public visibility is needed
- For setters, any visibility is ok (including private)
What this feature adds, then, is ability to define explicit minimum visibility levels for all these types separately. This is done by combination of:
Using additional properties of JsonAutoDetect for changing per-class (and sub-class via annotation inheritance, mix-ins) defaults: @JsonAutoDetect(getterVisibility=Visibility.ANY) and so on
Redefining global defaults using ObjectMapper.setVisibilityChecker()
The new interface, VisibilityChecker is actual powerful enough abstraction to allow almost many more kinds of visibility detection (including ones that are not even based on basic Java access modifiers). But its default implementation (VisibilityChecker.Std) uses simple access-modifier - based approach, and can be used as basis for more complex scenarios.
Further additions for 1.9
Jackson 1.9 further adds couple of convenience methods, so that you can for example do:
ObjectMapper mapper = new ObjectMapper();
mapper.setVisibility(JsonMethod.FIELD, JsonAutoDetect.Visibility.ANY) // auto-detect all member fields
.setVisibility(JsonMethod.GETTER, JsonAutoDetect.Visibility.NONE) // but only public getters
.setVisibility(JsonMethod.IS_GETTER, JsonAutoDetect.Visibility.NONE) // and none of "is-setters"
;or, to disable all auto-detection:
ObjectMapper mapper = new ObjectMapper(); mapper.setVisibilityChecker(mapper.getVisibilityChecker.with(JsonAutoDetect.Visibility.NONE));
