Working on refactoring auto-detection handling.
diff --git a/src/java/org/codehaus/jackson/annotate/JsonAutoDetect.java b/src/java/org/codehaus/jackson/annotate/JsonAutoDetect.java
index b3d0c89..8eac37e 100644
--- a/src/java/org/codehaus/jackson/annotate/JsonAutoDetect.java
+++ b/src/java/org/codehaus/jackson/annotate/JsonAutoDetect.java
@@ -69,7 +69,14 @@
* this can be essentially used to disable auto-detection for specified
* types.
*/
- NONE;
+ NONE,
+
+ /**
+ * Value that indicates that default visibility level (whatever it is,
+ * depends on context) is to be used. This usually means that inherited
+ * value (from parent visibility settings) is to be used.
+ */
+ DEFAULT;
public boolean isVisible(Member m) {
switch (this) {
@@ -98,24 +105,39 @@
JsonMethod[] value() default { JsonMethod.ALL };
/**
- * Minimum visibility required for auto-detecting getter methods.
+ * Minimum visibility required for auto-detecting regular getter methods.
+ *
+ * @since 1.5
*/
Visibility getterVisibility() default Visibility.PUBLIC_ONLY;
/**
+ * Minimum visibility required for auto-detecting is-getter methods.
+ *
+ * @since 1.5
+ */
+ Visibility isGetterVisibility() default Visibility.PUBLIC_ONLY;
+
+ /**
* Minimum visibility required for auto-detecting setter methods.
+ *
+ * @since 1.5
*/
Visibility setterVisibility() default Visibility.ANY;
/**
- * Minimum visibility required for auto-detecting member fields.
- */
- Visibility fieldVisibility() default Visibility.PUBLIC_ONLY;
-
- /**
* Minimum visibility required for auto-detecting Creator methods,
* except for no-argument constructors (which are always detected
* no matter what).
+ *
+ * @since 1.5
*/
Visibility creatorVisibility() default Visibility.PUBLIC_ONLY;
+
+ /**
+ * Minimum visibility required for auto-detecting member fields.
+ *
+ * @since 1.5
+ */
+ Visibility fieldVisibility() default Visibility.PUBLIC_ONLY;
}
diff --git a/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java b/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java
index b5c5818..5bc9226 100644
--- a/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java
+++ b/src/mapper/java/org/codehaus/jackson/map/AnnotationIntrospector.java
@@ -95,15 +95,6 @@
public abstract Boolean findCachability(AnnotatedClass ac);
/**
- * Method for checking whether there is a class annotation that
- * indicates whether field auto detection should be enabled.
- *
- * @return null if no relevant annotation is located; Boolean.TRUE
- * if enabling annotation found, Boolean.FALSE if disabling annotation
- */
- public abstract Boolean findFieldAutoDetection(AnnotatedClass ac);
-
- /**
* Method for locating name used as "root name" (for use by
* some serializers when outputting root-level object -- mostly
* for XML compatibility purposes) for given class, if one
@@ -133,6 +124,79 @@
public abstract Boolean findIgnoreUnknownProperties(AnnotatedClass ac);
/*
+ /******************************************************
+ /* Property auto-detection
+ /******************************************************
+ */
+
+ /**
+ * Method for checking whether there is a class annotation that
+ * indicates whether field auto detection should be enabled.
+ *
+ * @return null if no relevant annotation is located; Boolean.TRUE
+ * if enabling annotation found, Boolean.FALSE if disabling annotation
+ */
+ public abstract Boolean findFieldAutoDetection(AnnotatedClass ac);
+
+
+ /**
+ * Method for checking whether there is a class annotation that
+ * indicates whether (regular) getter-method auto detection
+ * should be enabled.
+ * Getter methods are methods with name "getXxx()" (for property "xxx");
+ * "isXxx()" are not included (instead those are considered
+ * "is getters")
+ *
+ * @return null if no relevant annotation is located; Boolean.TRUE
+ * if enabling annotation found, Boolean.FALSE if disabling annotation
+ */
+ public abstract Boolean findGetterAutoDetection(AnnotatedClass ac);
+
+ /**
+ * Method for checking whether there is a class annotation that
+ * indicates whether getter-method auto-detection for "is getters"
+ * should be enabled.
+ * Is-getter methods are methods with name "isXxx()" (for property "xxx").
+ *
+ * @since 1.3
+ *
+ * @return null if no relevant annotation is located; Boolean.TRUE
+ * if enabling annotation found, Boolean.FALSE if disabling annotation
+ */
+ public abstract Boolean findIsGetterAutoDetection(AnnotatedClass ac);
+
+ /**
+ * Method for checking whether there is a class annotation that
+ * indicates whether creator-method auto detection should be enabled.
+ *
+ * @return null if no relevant annotation is located; Boolean.TRUE
+ * if enabling annotation found, Boolean.FALSE if disabling annotation
+ */
+ public abstract Boolean findCreatorAutoDetection(AnnotatedClass ac);
+
+ /**
+ * Method for checking whether there is a class annotation that
+ * indicates whether setter-method auto detection should be enabled.
+ *
+ * @return null if no relevant annotation is located; Boolean.TRUE
+ * if enabling annotation found, Boolean.FALSE if disabling annotation
+ */
+ public abstract Boolean findSetterAutoDetection(AnnotatedClass ac);
+
+
+ /**
+ * Method for checking if annotations indicate changes to minimum visibility levels
+ * needed for auto-detecting property elements (fields, methods, constructors).
+ * A baseline checker is given, and introspector is to either return it as is (if
+ * no annotations are found), or build and return a derived instance (using checker's build
+ * methods).
+ *
+ * @since 1.5
+ */
+ public abstract VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
+ VisibilityChecker<?> baseChecker);
+
+ /*
/****************************************************
/* Class annotations for PM type handling (1.5+)
/****************************************************
@@ -324,34 +388,6 @@
*/
/**
- * Method for checking whether there is a class annotation that
- * indicates whether (regular) getter-method auto detection
- * should be enabled.
- * Getter methods are methods with name "getXxx()" (for property "xxx");
- * "isXxx()" are not included (instead those are considered
- * "is getters")
- *
- * @return null if no relevant annotation is located; Boolean.TRUE
- * if enabling annotation found, Boolean.FALSE if disabling annotation
- */
- public abstract Boolean findGetterAutoDetection(AnnotatedClass ac);
-
- /**
- * Method for checking whether there is a class annotation that
- * indicates whether (regular) getter-method auto detection
- * should be enabled.
- * Getter methods are methods with name "getXxx()" (for property "xxx");
- * "isXxx()" are not included (instead those are considered
- * "is getters")
- *
- * @since 1.3
- *
- * @return null if no relevant annotation is located; Boolean.TRUE
- * if enabling annotation found, Boolean.FALSE if disabling annotation
- */
- public abstract Boolean findIsGetterAutoDetection(AnnotatedClass ac);
-
- /**
* Method for accessing defined property serialization order (which may be
* partial). May return null if no ordering is defined.
*
@@ -519,24 +555,6 @@
/******************************************************
*/
- /**
- * Method for checking whether there is a class annotation that
- * indicates whether creator-method auto detection should be enabled.
- *
- * @return null if no relevant annotation is located; Boolean.TRUE
- * if enabling annotation found, Boolean.FALSE if disabling annotation
- */
- public abstract Boolean findCreatorAutoDetection(AnnotatedClass ac);
-
- /**
- * Method for checking whether there is a class annotation that
- * indicates whether setter-method auto detection should be enabled.
- *
- * @return null if no relevant annotation is located; Boolean.TRUE
- * if enabling annotation found, Boolean.FALSE if disabling annotation
- */
- public abstract Boolean findSetterAutoDetection(AnnotatedClass ac);
-
/*
///////////////////////////////////////////////////////
// Deserialization: method annotations
@@ -685,16 +703,6 @@
}
return result;
}
-
- @Override
- public Boolean findFieldAutoDetection(AnnotatedClass ac)
- {
- Boolean result = _primary.findFieldAutoDetection(ac);
- if (result == null) {
- result = _secondary.findFieldAutoDetection(ac);
- }
- return result;
- }
@Override
public String findRootName(AnnotatedClass ac)
@@ -730,6 +738,79 @@
return result;
}
+ /*
+ /******************************************************
+ /* Property auto-detection
+ /******************************************************
+ */
+
+ @Override
+ public Boolean findFieldAutoDetection(AnnotatedClass ac)
+ {
+ Boolean result = _primary.findFieldAutoDetection(ac);
+ if (result == null) {
+ result = _secondary.findFieldAutoDetection(ac);
+ }
+ return result;
+ }
+
+ @Override
+ public Boolean findGetterAutoDetection(AnnotatedClass ac)
+ {
+ Boolean result = _primary.findGetterAutoDetection(ac);
+ if (result == null) {
+ result = _secondary.findGetterAutoDetection(ac);
+ }
+ return result;
+ }
+
+ @Override
+ public Boolean findIsGetterAutoDetection(AnnotatedClass ac)
+ {
+ Boolean result = _primary.findIsGetterAutoDetection(ac);
+ if (result == null) {
+ result = _secondary.findIsGetterAutoDetection(ac);
+ }
+ return result;
+ }
+
+ @Override
+ public Boolean findCreatorAutoDetection(AnnotatedClass ac)
+ {
+ Boolean result = _primary.findCreatorAutoDetection(ac);
+ if (result == null) {
+ result = _secondary.findCreatorAutoDetection(ac);
+ }
+ return result;
+ }
+
+ @Override
+ public Boolean findSetterAutoDetection(AnnotatedClass ac)
+ {
+ Boolean result = _primary.findSetterAutoDetection(ac);
+ if (result == null) {
+ result = _secondary.findSetterAutoDetection(ac);
+ }
+ return result;
+ }
+
+ @Override
+ public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
+ VisibilityChecker<?> checker)
+ {
+ /* Note: to have proper priorities, we must actually call delegatees
+ * in reverse order:
+ */
+ checker = _secondary.findAutoDetectVisibility(ac, checker);
+ return _primary.findAutoDetectVisibility(ac, checker);
+ }
+
+ /*
+ /******************************************************
+ /* Type handling
+ /******************************************************
+ */
+
@Override
public TypeResolverBuilder<?> findTypeResolver(AnnotatedClass ac, JavaType baseType)
{
@@ -877,25 +958,6 @@
// // // Serialization: class annotations
- @Override
- public Boolean findGetterAutoDetection(AnnotatedClass ac)
- {
- Boolean result = _primary.findGetterAutoDetection(ac);
- if (result == null) {
- result = _secondary.findGetterAutoDetection(ac);
- }
- return result;
- }
-
- @Override
- public Boolean findIsGetterAutoDetection(AnnotatedClass ac)
- {
- Boolean result = _primary.findIsGetterAutoDetection(ac);
- if (result == null) {
- result = _secondary.findIsGetterAutoDetection(ac);
- }
- return result;
- }
public String[] findSerializationPropertyOrder(AnnotatedClass ac) {
String[] result = _primary.findSerializationPropertyOrder(ac);
@@ -1039,27 +1101,6 @@
return result;
}
- // // // Deserialization: class annotations
-
- @Override
- public Boolean findCreatorAutoDetection(AnnotatedClass ac)
- {
- Boolean result = _primary.findCreatorAutoDetection(ac);
- if (result == null) {
- result = _secondary.findCreatorAutoDetection(ac);
- }
- return result;
- }
-
- @Override
- public Boolean findSetterAutoDetection(AnnotatedClass ac)
- {
- Boolean result = _primary.findSetterAutoDetection(ac);
- if (result == null) {
- result = _secondary.findSetterAutoDetection(ac);
- }
- return result;
- }
// // // Deserialization: method annotations
diff --git a/src/mapper/java/org/codehaus/jackson/map/introspect/JacksonAnnotationIntrospector.java b/src/mapper/java/org/codehaus/jackson/map/introspect/JacksonAnnotationIntrospector.java
index 26bb0e9..73c4c4b 100644
--- a/src/mapper/java/org/codehaus/jackson/map/introspect/JacksonAnnotationIntrospector.java
+++ b/src/mapper/java/org/codehaus/jackson/map/introspect/JacksonAnnotationIntrospector.java
@@ -119,6 +119,14 @@
return (ignore == null) ? null : ignore.ignoreUnknown();
}
+ @Override
+ public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
+ VisibilityChecker<?> checker)
+ {
+ JsonAutoDetect ann = ac.getAnnotation(JsonAutoDetect.class);
+ return (ann == null) ? checker : checker.with(ann);
+ }
+
/*
/****************************************************
/* Class annotations for PM type handling (1.5+)
diff --git a/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java b/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java
index d0c2edf..6c7a022 100644
--- a/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java
+++ b/src/mapper/java/org/codehaus/jackson/map/introspect/NopAnnotationIntrospector.java
@@ -85,6 +85,11 @@
return null;
}
+ @Override
+ public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac, VisibilityChecker<?> checker) {
+ return checker;
+ }
+
/*
/****************************************************
/* Class annotations for PM type handling (1.5+)
diff --git a/src/mapper/java/org/codehaus/jackson/map/introspect/VisibilityChecker.java b/src/mapper/java/org/codehaus/jackson/map/introspect/VisibilityChecker.java
index 073006c..3b13e4b 100644
--- a/src/mapper/java/org/codehaus/jackson/map/introspect/VisibilityChecker.java
+++ b/src/mapper/java/org/codehaus/jackson/map/introspect/VisibilityChecker.java
@@ -2,6 +2,7 @@
import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
+import org.codehaus.jackson.annotate.JsonMethod;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
@@ -20,140 +21,271 @@
*/
public interface VisibilityChecker<T extends VisibilityChecker<T>>
{
- // // Builder
+ // // Builder methods
- public T withGetterVisibility(Visibility v);
- public T withSetterVisibility(Visibility v);
- public T withCreatorVisibility(Visibility v);
- public T withFieldVisibility(Visibility v);
+ /**
+ * Builder method that will return an instance that has same
+ * settings as this instance has, except for values that
+ * given annotation overrides.
+ */
+ public T with(JsonAutoDetect ann);
+
+ /**
+ * Builder method that will return a checker instance that has
+ * specified minimum visibility level for regular ("getXxx") getters.
+ */
+ public T withGetterVisibility(Visibility v);
+
+ /**
+ * Builder method that will return a checker instance that has
+ * specified minimum visibility level for "is-getters" ("isXxx").
+ */
+ public T withIsGetterVisibility(Visibility v);
+
+ /**
+ * Builder method that will return a checker instance that has
+ * specified minimum visibility level for setters.
+ */
+ public T withSetterVisibility(Visibility v);
+
+ /**
+ * Builder method that will return a checker instance that has
+ * specified minimum visibility level for creator methods
+ * (constructors, factory methods)
+ */
+ public T withCreatorVisibility(Visibility v);
+
+ /**
+ * Builder method that will return a checker instance that has
+ * specified minimum visibility level for fields.
+ */
+ public T withFieldVisibility(Visibility v);
- // // Accessors
+ // // Accessors
- public boolean isGetterVisible(Method m);
- public boolean isGetterVisible(AnnotatedMethod m);
+ /**
+ * Method for checking whether given method is auto-detectable
+ * as regular getter, with respect to its visibility (not considering
+ * method signature or name, just visibility)
+ */
+ public boolean isGetterVisible(Method m);
+ public boolean isGetterVisible(AnnotatedMethod m);
- public boolean isSetterVisible(Method m);
- public boolean isSetterVisible(AnnotatedMethod m);
+ /**
+ * Method for checking whether given method is auto-detectable
+ * as is-getter, with respect to its visibility (not considering
+ * method signature or name, just visibility)
+ */
+ public boolean isIsGetterVisible(Method m);
+ public boolean isIsGetterVisible(AnnotatedMethod m);
+
+ /**
+ * Method for checking whether given method is auto-detectable
+ * as setter, with respect to its visibility (not considering
+ * method signature or name, just visibility)
+ */
+ public boolean isSetterVisible(Method m);
+ public boolean isSetterVisible(AnnotatedMethod m);
- public boolean isCreatorVisible(Member m);
- public boolean isCreatorVisible(AnnotatedMember m);
+ /**
+ * Method for checking whether given method is auto-detectable
+ * as Creator, with respect to its visibility (not considering
+ * method signature or name, just visibility)
+ */
+ public boolean isCreatorVisible(Member m);
+ public boolean isCreatorVisible(AnnotatedMember m);
- public boolean isFieldVisible(Field f);
- public boolean isFieldVisible(AnnotatedField f);
+ /**
+ * Method for checking whether given field is auto-detectable
+ * as property, with respect to its visibility (not considering
+ * method signature or name, just visibility)
+ */
+ public boolean isFieldVisible(Field f);
+ public boolean isFieldVisible(AnnotatedField f);
- /*
- /********************************************************
+ /*
+ /********************************************************
/* Standard implementation suitable for basic use
- /********************************************************
- */
+ /********************************************************
+ */
+
+ /**
+ * Default standard implementation is purely based on visibility
+ * modifier of given class members, and its configured minimum
+ * levels.
+ * Implemented using "builder" (aka "Fluid") pattern, whereas instances
+ * are immutable, and configuration is achieved by chainable factory
+ * methods. As a result, type is declared is funky recursive generic
+ * type, to allow for sub-classing of build methods with property type
+ * co-variance.
+ *<p>
+ * Note on <code>JsonAutoDetect</code> annotation: it is used to
+ * access default minimum visibility access definitions.
+ */
+ @JsonAutoDetect(
+ getterVisibility = Visibility.PUBLIC_ONLY,
+ isGetterVisibility = Visibility.PUBLIC_ONLY,
+ setterVisibility = Visibility.ANY,
+ creatorVisibility = Visibility.PUBLIC_ONLY,
+ fieldVisibility = Visibility.PUBLIC_ONLY
+ )
+ public static class Std
+ implements VisibilityChecker<Std>
+ {
+ protected final Visibility _getterMinLevel;
+ protected final Visibility _isGetterMinLevel;
+ protected final Visibility _setterMinLevel;
+ protected final Visibility _creatorMinLevel;
+ protected final Visibility _fieldMinLevel;
+
+ /**
+ * Default constructor; will construct an instance that uses default
+ * Jackson visibility limits, as indicated by {@link JsonAutoDetect}
+ * settings for this class.
+ */
+ public Std() {
+ this(Std.class.getAnnotation(JsonAutoDetect.class));
+ }
+
+ /**
+ * Constructor used for building instance that has minumum visibility
+ * levels as indicated by given annotation instance
+ *
+ * @param ann Annotations to use for determining minimum visibility levels
+ */
+ public Std(JsonAutoDetect ann)
+ {
+ JsonMethod[] incl = ann.value();
+ // let's combine checks for enabled/disabled, with minimimum level checks:
+ _getterMinLevel = hasMethod(incl, JsonMethod.GETTER) ? ann.getterVisibility() : Visibility.NONE;
+ _isGetterMinLevel = hasMethod(incl, JsonMethod.IS_GETTER) ? ann.isGetterVisibility() : Visibility.NONE;
+ _setterMinLevel = hasMethod(incl, JsonMethod.SETTER) ? ann.setterVisibility() : Visibility.NONE;
+ _creatorMinLevel = hasMethod(incl, JsonMethod.CREATOR) ? ann.creatorVisibility() : Visibility.NONE;
+ _fieldMinLevel = hasMethod(incl, JsonMethod.FIELD) ? ann.fieldVisibility() : Visibility.NONE;
+ }
/**
- * Default standard implementation is purely based on visibility
- * modifier of given class members, and its configured minimum
- * levels.
- * Implemented using "builder" (aka "Fluid") pattern, whereas instances
- * are immutable, and configuration is achieved by chainable factory
- * methods. As a result, type is declared is funky recursive generic
- * type, to allow for sub-classing of build methods with property type
- * co-variance.
- *<p>
- * Note on <code>JsonAutoDetect</code> annotation: it is used to
- * access default minimum visibility access needed.
+ * Constructor that allows directly specifying minimum visibility levels to use
*/
- @JsonAutoDetect()
- public static class Std
- implements VisibilityChecker<Std>
- {
- protected final Visibility _getterMinLevel;
- protected final Visibility _setterMinLevel;
- protected final Visibility _creatorMinLevel;
- protected final Visibility _fieldMinLevel;
+ public Std(Visibility getter, Visibility isGetter, Visibility setter, Visibility creator, Visibility field)
+ {
+ _getterMinLevel = getter;
+ _isGetterMinLevel = isGetter;
+ _setterMinLevel = setter;
+ _creatorMinLevel = creator;
+ _fieldMinLevel = field;
+ }
- /**
- * Default constructor uses default {@link JsonAutoDetect}
- * limits.
- */
- public Std() {
- this(Std.class.getAnnotation(JsonAutoDetect.class));
- }
+ /*
+ /********************************************************
+ /* Builder/fluid methods for instantiating configured
+ /* instances
+ /********************************************************
+ */
- public Std(JsonAutoDetect ann)
- {
- _getterMinLevel = ann.getterVisibility();
- _setterMinLevel = ann.setterVisibility();
- _creatorMinLevel = ann.creatorVisibility();
- _fieldMinLevel = ann.fieldVisibility();
- }
+ public Std with(JsonAutoDetect ann)
+ {
+ if (ann == null) return this;
+ Std curr = this;
+
+ JsonMethod[] incl = ann.value();
+ Visibility v;
+
+ v = hasMethod(incl, JsonMethod.GETTER) ? ann.getterVisibility() : Visibility.NONE;
+ curr = curr.withGetterVisibility(v);
+ v = hasMethod(incl, JsonMethod.IS_GETTER) ? ann.isGetterVisibility() : Visibility.NONE;
+ curr = curr.withIsGetterVisibility(v);
+ v = hasMethod(incl, JsonMethod.SETTER) ? ann.setterVisibility() : Visibility.NONE;
+ curr = curr.withSetterVisibility(v);
+ v = hasMethod(incl, JsonMethod.CREATOR) ? ann.creatorVisibility() : Visibility.NONE;
+ curr = curr.withCreatorVisibility(v);
+ v = hasMethod(incl, JsonMethod.FIELD) ? ann.fieldVisibility() : Visibility.NONE;
+ curr = curr.withFieldVisibility(v);
+ return curr;
+ }
+
+ public Std withGetterVisibility(Visibility v) {
+ if (_getterMinLevel == v || v == Visibility.DEFAULT) return this;
+ return new Std(v, _isGetterMinLevel, _setterMinLevel, _creatorMinLevel, _fieldMinLevel);
+ }
+
+ public Std withIsGetterVisibility(Visibility v) {
+ if (_isGetterMinLevel == v || v == Visibility.DEFAULT) return this;
+ return new Std(_getterMinLevel, v, _setterMinLevel, _creatorMinLevel, _fieldMinLevel);
+ }
- public Std(Visibility getter, Visibility setter, Visibility creator, Visibility field)
- {
- _getterMinLevel = getter;
- _setterMinLevel = setter;
- _creatorMinLevel = creator;
- _fieldMinLevel = field;
- }
+ public Std withSetterVisibility(Visibility v) {
+ if (_setterMinLevel == v || v == Visibility.DEFAULT) return this;
+ return new Std(_getterMinLevel, _isGetterMinLevel, v, _creatorMinLevel, _fieldMinLevel);
+ }
+
+ public Std withCreatorVisibility(Visibility v) {
+ if (_creatorMinLevel == v || v == Visibility.DEFAULT) return this;
+ return new Std(_getterMinLevel, _isGetterMinLevel, _setterMinLevel, v, _fieldMinLevel);
+ }
+
+ public Std withFieldVisibility(Visibility v) {
+ if (_fieldMinLevel == v || v == Visibility.DEFAULT) return this;
+ return new Std(_getterMinLevel, _isGetterMinLevel, _setterMinLevel, _creatorMinLevel, v);
+ }
- /*
- /********************************************************
- /* Builder/fluid methods for instantiating configured
- /* instances
- /********************************************************
- */
+ /*
+ /********************************************************
+ /* Public API impl
+ /********************************************************
+ */
- public Std withGetterVisibility(Visibility v) {
- return new Std(v, _setterMinLevel, _creatorMinLevel, _fieldMinLevel);
- }
+ public boolean isCreatorVisible(Member m) {
+ return _creatorMinLevel.isVisible(m);
+ }
+
+ public boolean isCreatorVisible(AnnotatedMember m) {
+ return isCreatorVisible(m.getMember());
+ }
+
+ public boolean isFieldVisible(Field f) {
+ return _fieldMinLevel.isVisible(f);
+ }
+
+ public boolean isFieldVisible(AnnotatedField f) {
+ return isFieldVisible(f.getAnnotated());
+ }
+
+ public boolean isGetterVisible(Method m) {
+ return _getterMinLevel.isVisible(m);
+ }
+ public boolean isGetterVisible(AnnotatedMethod m) {
+ return isGetterVisible(m.getAnnotated());
+ }
- public Std withSetterVisibility(Visibility v) {
- return new Std(_getterMinLevel, v, _creatorMinLevel, _fieldMinLevel);
- }
+ public boolean isIsGetterVisible(Method m) {
+ return _isGetterMinLevel.isVisible(m);
+ }
- public Std withCreatorVisibility(Visibility v) {
- return new Std(_getterMinLevel, _setterMinLevel, v, _fieldMinLevel);
- }
+ public boolean isIsGetterVisible(AnnotatedMethod m) {
+ return isIsGetterVisible(m.getAnnotated());
+ }
- public Std withFieldVisibility(Visibility v) {
- return new Std(_getterMinLevel, _setterMinLevel, _creatorMinLevel, v);
- }
-
- /*
- /********************************************************
- /* Public API impl
- /********************************************************
- */
+ public boolean isSetterVisible(Method m) {
+ return _setterMinLevel.isVisible(m);
+ }
+
+ public boolean isSetterVisible(AnnotatedMethod m) {
+ return isSetterVisible(m.getAnnotated());
+ }
-
- public boolean isCreatorVisible(Member m) {
- return _creatorMinLevel.isVisible(m);
- }
-
- public boolean isCreatorVisible(AnnotatedMember m) {
- return isCreatorVisible(m.getMember());
- }
-
- public boolean isFieldVisible(Field f) {
- return _fieldMinLevel.isVisible(f);
- }
-
- public boolean isFieldVisible(AnnotatedField f) {
- return isFieldVisible(f.getAnnotated());
- }
-
- public boolean isGetterVisible(Method m) {
- return _getterMinLevel.isVisible(m);
- }
-
- public boolean isGetterVisible(AnnotatedMethod m) {
- return isGetterVisible(m.getAnnotated());
- }
-
- public boolean isSetterVisible(Method m) {
- return _setterMinLevel.isVisible(m);
- }
-
- public boolean isSetterVisible(AnnotatedMethod m) {
- return isSetterVisible(m.getAnnotated());
- }
+ /*
+ /********************************************************
+ /* Helper methods
+ /********************************************************
+ */
+
+ private static boolean hasMethod(JsonMethod[] methods, JsonMethod method)
+ {
+ for (JsonMethod curr : methods) {
+ if (curr == method || curr == JsonMethod.ALL) return true;
+ }
+ return false;
+ }
}
-
}
diff --git a/src/xc/java/org/codehaus/jackson/xc/JaxbAnnotationIntrospector.java b/src/xc/java/org/codehaus/jackson/xc/JaxbAnnotationIntrospector.java
index be49a8c..c586c55 100644
--- a/src/xc/java/org/codehaus/jackson/xc/JaxbAnnotationIntrospector.java
+++ b/src/xc/java/org/codehaus/jackson/xc/JaxbAnnotationIntrospector.java
@@ -13,6 +13,7 @@
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
+import org.codehaus.jackson.annotate.JsonAutoDetect.Visibility;
import org.codehaus.jackson.annotate.JsonTypeInfo;
import org.codehaus.jackson.map.AnnotationIntrospector;
import org.codehaus.jackson.map.JsonDeserializer;
@@ -28,18 +29,19 @@
/**
* Annotation introspector that leverages JAXB annotations where applicable to JSON mapping.
* <p/>
- * The following JAXB annotations were determined to be not-applicable:
+ * The following JAXB annotations are not supported yet (but some may be supported in future)
* <ul>
- * <li>{@link XmlAnyAttribute} because it applies only to Map<QName, String>, which jackson can't serialize
- * <li>{@link XmlAnyElement} because it applies only to JAXBElement, which jackson can't serialize
- * <li>{@link javax.xml.bind.annotation.XmlAttachmentRef}: JSON does not support
- * external attachments
+ * <li>{@link XmlAnyAttribute} not yet used (as of 1.5) but may be in future (as an alias for @JsonAnySetter?)
+ * <li>{@link XmlAnyElement} not yet used, may be as per [JACKSON-253]
+ * <li>{@link javax.xml.bind.annotation.XmlAttachmentRef}: JSON does not support external attachments
* <li>{@link XmlElementDecl}
- * <li>{@link XmlElementRefs} because Jackson doesn't have any support for 'named' collection items.
- * <li>{@link XmlID} because Jackson doesn't support referential integrity.
- * <li>{@link XmlIDREF} because the is no JSON support for referential integrity.
+ * <li>{@link XmlElementRefs} because Jackson doesn't have any support for 'named' collection items -- however,
+ * this may become partially supported as per [JACKSON-253].
+ * <li>{@link XmlID} because Jackson doesn't support referential integrity. NOTE: this too may be supported
+ * in future if/when id references are handled
+ * <li>{@link XmlIDREF} same as <code>XmlID</code>
* <li>{@link javax.xml.bind.annotation.XmlInlineBinaryData} since the underlying concepts
- * (like XOP) do not exist in JSON
+ * (like XOP) do not exist in JSON -- Jackson will always use inline base64 encoding as the method
* <li>{@link javax.xml.bind.annotation.XmlList} because JSON does have (or necessarily need)
* method of serializing list of values as space-separated Strings
* <li>{@link javax.xml.bind.annotation.XmlMimeType}
@@ -227,6 +229,45 @@
return null;
}
+ @Override
+ public VisibilityChecker<?> findAutoDetectVisibility(AnnotatedClass ac,
+ VisibilityChecker<?> checker)
+ {
+ XmlAccessType at = findAccessType(ac);
+ if (at == null) return checker;
+
+ // Note: JAXB does not do creator auto-detection, can ignore
+ switch (at) {
+ case FIELD: // all fields, independent of visibility; no methods
+ return checker.withFieldVisibility(Visibility.ANY)
+ .withSetterVisibility(Visibility.NONE)
+ .withGetterVisibility(Visibility.NONE)
+ .withIsGetterVisibility(Visibility.NONE)
+ ;
+ case NONE: // no auto-detection
+ return checker.withFieldVisibility(Visibility.NONE)
+ .withSetterVisibility(Visibility.NONE)
+ .withGetterVisibility(Visibility.NONE)
+ .withIsGetterVisibility(Visibility.NONE)
+ ;
+ case PROPERTY:
+ return checker.withFieldVisibility(Visibility.NONE)
+ .withSetterVisibility(Visibility.PUBLIC_ONLY)
+ .withGetterVisibility(Visibility.PUBLIC_ONLY)
+ .withIsGetterVisibility(Visibility.PUBLIC_ONLY)
+ ;
+ case PUBLIC_MEMBER:
+ return checker.withFieldVisibility(Visibility.PUBLIC_ONLY)
+ .withSetterVisibility(Visibility.PUBLIC_ONLY)
+ .withGetterVisibility(Visibility.PUBLIC_ONLY)
+ .withIsGetterVisibility(Visibility.PUBLIC_ONLY)
+ ;
+ //boolean enabled = (at == XmlAccessType.PUBLIC_MEMBER) || (at == XmlAccessType.PROPERTY);
+ //return enabled ? Boolean.TRUE : Boolean.FALSE;
+ }
+ return checker;
+ }
+
/*
/****************************************************
/* Class annotations for PM type handling (1.5+)