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:

However: this only allows enabling/disabling auto-detection, but not changing what visibility level is required. Existing settings were (and are) such that:

What this feature adds, then, is ability to define explicit minimum visibility levels for all these types separately. This is done by combination of:

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));


CategoryJackson

JacksonFeatureAutoDetect (last edited 2011-07-19 02:26:12 by TatuSaloranta)

Copyright ©2009 FasterXML, LLC