diff --git a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java index c15d8c08d1..6bdec2f38c 100644 --- a/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/AnnotationIntrospector.java @@ -183,14 +183,15 @@ public boolean isAnnotationBundle(Annotation ann) { * having precedence) should include Object Identifier, * and if so, specify details of Object Identity used. */ - public ObjectIdInfo findObjectIdInfo(Annotated ann) { + public ObjectIdInfo findObjectIdInfo(MapperConfig config, Annotated ann) { return null; } /** * Method for figuring out additional properties of an Object Identity reference */ - public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) { + public ObjectIdInfo findObjectReferenceInfo(MapperConfig config, + Annotated ann, ObjectIdInfo objectIdInfo) { return objectIdInfo; } @@ -206,9 +207,6 @@ public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectId * for XML compatibility purposes) for given class, if one * is defined. Returns null if no declaration found; can return * explicit empty String, which is usually ignored as well as null. - *

- * NOTE: method signature changed in 2.1, to return {@link PropertyName} - * instead of String. */ public PropertyName findRootName(AnnotatedClass ac) { return null; @@ -280,7 +278,8 @@ public JsonIgnoreProperties.Value findPropertyIgnorals(Annotated ac) * (if no annotations are found), or build and return a derived instance (using * checker's build methods). */ - public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, VisibilityChecker checker) { + public VisibilityChecker findAutoDetectVisibility(MapperConfig config, + AnnotatedClass ac, VisibilityChecker checker) { return checker; } @@ -315,70 +314,6 @@ public Object findTypeIdResolver(MapperConfig config, Annotated ann) { return null; } - /** - * Method for checking if given class has annotations that indicate - * that specific type resolver is to be used for handling instances. - * This includes not only - * instantiating resolver builder, but also configuring it based on - * relevant annotations (not including ones checked with a call to - * {@link #findSubtypes} - * - * @param config Configuration settings in effect (for serialization or deserialization) - * @param baseType Base java type of value for which resolver is to be found - * - * @return Type resolver builder for given type, if one found; null if none - */ - /* - public TypeResolverBuilder findTypeResolver(MapperConfig config, - Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo) { - return null; - } - */ - - /** - * Method for checking if given property entity (field or method) has annotations - * that indicate that specific type resolver is to be used for handling instances. - * This includes not only - * instantiating resolver builder, but also configuring it based on - * relevant annotations (not including ones checked with a call to - * {@link #findSubtypes} - * - * @param config Configuration settings in effect (for serialization or deserialization) - * @param baseType Base java type of property for which resolver is to be found - * - * @return Type resolver builder for properties of given entity, if one found; - * null if none - */ - /* - public TypeResolverBuilder findPropertyTypeResolver(MapperConfig config, - Annotated ann, JavaType baseType, JsonTypeInfo.Value typeInfo) { - return null; - } - */ - - /** - * Method for checking if given structured property entity (field or method that - * has nominal value of Map, Collection or array type) has annotations - * that indicate that specific type resolver is to be used for handling type - * information of contained values. - * This includes not only - * instantiating resolver builder, but also configuring it based on - * relevant annotations (not including ones checked with a call to - * {@link #findSubtypes} - * - * @param config Configuration settings in effect (for serialization or deserialization) - * @param containerType Type of property for which resolver is to be found (must be a container type) - * - * @return Type resolver builder for values contained in properties of given entity, - * if one found; null if none - */ - /* - public TypeResolverBuilder findPropertyContentTypeResolver(MapperConfig config, - Annotated ann, JavaType containerType, JsonTypeInfo.Value typeInfo) { - return null; - } - */ - /** * Method for locating annotation-specified subtypes related to annotated * entity (class, method, field). Note that this is only guaranteed to be diff --git a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java index 996f26b4a8..dc0909b2f4 100644 --- a/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/cfg/MapperConfigBase.java @@ -521,11 +521,12 @@ public final VisibilityChecker getDefaultVisibilityChecker() @Override public final VisibilityChecker getDefaultVisibilityChecker(Class baseType, - AnnotatedClass actualClass) { + AnnotatedClass actualClass) + { VisibilityChecker vc = getDefaultVisibilityChecker(); AnnotationIntrospector intr = getAnnotationIntrospector(); if (intr != null) { - vc = intr.findAutoDetectVisibility(actualClass, vc); + vc = intr.findAutoDetectVisibility(this, actualClass, vc); } ConfigOverride overrides = _configOverrides.findOverride(baseType); if (overrides != null) { diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/AbstractDeserializer.java b/src/main/java/com/fasterxml/jackson/databind/deser/AbstractDeserializer.java index 00287f61d7..f360db9375 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/AbstractDeserializer.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/AbstractDeserializer.java @@ -119,7 +119,7 @@ public JsonDeserializer createContextual(DeserializationContext ctxt, if (property != null && intr != null) { final AnnotatedMember accessor = property.getMember(); if (accessor != null) { - ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); + ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(ctxt.getConfig(), accessor); if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory) JavaType idType; ObjectIdGenerator idGen; @@ -127,7 +127,7 @@ public JsonDeserializer createContextual(DeserializationContext ctxt, ObjectIdResolver resolver = ctxt.objectIdResolverInstance(accessor, objectIdInfo); // 2.1: allow modifications by "id ref" annotations as well: - objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); + objectIdInfo = intr.findObjectReferenceInfo(ctxt.getConfig(), accessor, objectIdInfo); Class implClass = objectIdInfo.getGeneratorType(); if (implClass == ObjectIdGenerators.PropertyGenerator.class) { diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java index 0f47afa262..734ff9cbbe 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerBase.java @@ -671,10 +671,10 @@ public JsonDeserializer createContextual(DeserializationContext ctxt, final AnnotationIntrospector intr = ctxt.getAnnotationIntrospector(); final AnnotatedMember accessor = _neitherNull(property, intr) ? property.getMember() : null; if (accessor != null) { - ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); + ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(ctxt.getConfig(), accessor); if (objectIdInfo != null) { // some code duplication here as well (from BeanDeserializerFactory) // 2.1: allow modifications by "id ref" annotations as well: - objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); + objectIdInfo = intr.findObjectReferenceInfo(ctxt.getConfig(), accessor, objectIdInfo); Class implClass = objectIdInfo.getGeneratorType(); // Property-based generator is trickier diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java index 13a646c67c..d20916eb33 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/AnnotationIntrospectorPair.java @@ -161,14 +161,14 @@ public String findClassDescription(AnnotatedClass ac) { */ @Override - public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, - VisibilityChecker checker) + public VisibilityChecker findAutoDetectVisibility(MapperConfig config, + 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); + checker = _secondary.findAutoDetectVisibility(config, ac, checker); + return _primary.findAutoDetectVisibility(config, ac, checker); } /* @@ -381,16 +381,17 @@ public Boolean isTypeId(MapperConfig config, AnnotatedMember member) { } @Override - public ObjectIdInfo findObjectIdInfo(Annotated ann) { - ObjectIdInfo r = _primary.findObjectIdInfo(ann); - return (r == null) ? _secondary.findObjectIdInfo(ann) : r; + public ObjectIdInfo findObjectIdInfo(MapperConfig config, Annotated ann) { + ObjectIdInfo r = _primary.findObjectIdInfo(config, ann); + return (r == null) ? _secondary.findObjectIdInfo(config, ann) : r; } @Override - public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) { + public ObjectIdInfo findObjectReferenceInfo(MapperConfig config, + Annotated ann, ObjectIdInfo objectIdInfo) { // to give precedence for primary, must start with secondary: - objectIdInfo = _secondary.findObjectReferenceInfo(ann, objectIdInfo); - objectIdInfo = _primary.findObjectReferenceInfo(ann, objectIdInfo); + objectIdInfo = _secondary.findObjectReferenceInfo(config, ann, objectIdInfo); + objectIdInfo = _primary.findObjectReferenceInfo(config, ann, objectIdInfo); return objectIdInfo; } diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java index 50a5acc226..6876814998 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/JacksonAnnotationIntrospector.java @@ -265,14 +265,14 @@ public String findClassDescription(AnnotatedClass ac) { } /* - /********************************************************** + /********************************************************************** /* Property auto-detection - /********************************************************** + /********************************************************************** */ @Override - public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, - VisibilityChecker checker) + public VisibilityChecker findAutoDetectVisibility(MapperConfig config, + AnnotatedClass ac, VisibilityChecker checker) { JsonAutoDetect ann = _findAnnotation(ac, JsonAutoDetect.class); if (ann == null) { @@ -591,7 +591,7 @@ public Boolean isTypeId(MapperConfig config, AnnotatedMember member) { */ @Override - public ObjectIdInfo findObjectIdInfo(Annotated ann) { + public ObjectIdInfo findObjectIdInfo(MapperConfig config, Annotated ann) { JsonIdentityInfo info = _findAnnotation(ann, JsonIdentityInfo.class); if (info == null || info.generator() == ObjectIdGenerators.None.class) { return null; @@ -602,7 +602,8 @@ public ObjectIdInfo findObjectIdInfo(Annotated ann) { } @Override - public ObjectIdInfo findObjectReferenceInfo(Annotated ann, ObjectIdInfo objectIdInfo) { + public ObjectIdInfo findObjectReferenceInfo(MapperConfig config, + Annotated ann, ObjectIdInfo objectIdInfo) { JsonIdentityReference ref = _findAnnotation(ann, JsonIdentityReference.class); if (ref == null) { return objectIdInfo; diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java index 560c41224f..5046f78f13 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertiesCollector.java @@ -246,9 +246,9 @@ public Set getIgnoredPropertyNames() { */ public ObjectIdInfo getObjectIdInfo() { - ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(_classDef); - if (info != null) { // 2.1: may also have different defaults for refs: - info = _annotationIntrospector.findObjectReferenceInfo(_classDef, info); + ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(_config, _classDef); + if (info != null) { + info = _annotationIntrospector.findObjectReferenceInfo(_config, _classDef, info); } return info; } diff --git a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java index 7dfb5a9034..5c682b3ecb 100644 --- a/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java +++ b/src/main/java/com/fasterxml/jackson/databind/introspect/POJOPropertyBuilder.java @@ -662,9 +662,9 @@ protected String _findDefaultValue() { public ObjectIdInfo findObjectIdInfo() { AnnotatedMember m = getPrimaryMember(); if (m != null) { - ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(m); + ObjectIdInfo info = _annotationIntrospector.findObjectIdInfo(_config, m); if (info != null) { - return _annotationIntrospector.findObjectReferenceInfo(m, info); + return _annotationIntrospector.findObjectReferenceInfo(_config, m, info); } } return null; diff --git a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java index ce72aac0fb..4001437486 100644 --- a/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java +++ b/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java @@ -432,11 +432,11 @@ public JsonSerializer createContextual(SerializerProvider provider, if (ignorals != null) { ignoredProps = ignorals.findIgnoredForSerialization(); } - ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(accessor); + ObjectIdInfo objectIdInfo = intr.findObjectIdInfo(config, accessor); if (objectIdInfo == null) { // no ObjectId override, but maybe ObjectIdRef? if (oiw != null) { - objectIdInfo = intr.findObjectReferenceInfo(accessor, null); + objectIdInfo = intr.findObjectReferenceInfo(config, accessor, null); if (objectIdInfo != null) { oiw = _objectIdWriter.withAlwaysAsId(objectIdInfo.getAlwaysAsId()); } @@ -446,7 +446,7 @@ public JsonSerializer createContextual(SerializerProvider provider, // to be able to move to SerializerProvider (where it really belongs) // 2.1: allow modifications by "id ref" annotations as well: - objectIdInfo = intr.findObjectReferenceInfo(accessor, objectIdInfo); + objectIdInfo = intr.findObjectReferenceInfo(config, accessor, objectIdInfo); ObjectIdGenerator gen; Class implClass = objectIdInfo.getGeneratorType(); JavaType type = provider.constructType(implClass); diff --git a/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java b/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java index 0d7b0a682c..86e8725040 100644 --- a/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/introspect/IntrospectorPairTest.java @@ -148,8 +148,8 @@ public String findClassDescription(AnnotatedClass ac) { */ @Override - public VisibilityChecker findAutoDetectVisibility(AnnotatedClass ac, - VisibilityChecker checker) + public VisibilityChecker findAutoDetectVisibility(MapperConfig config, + AnnotatedClass ac, VisibilityChecker checker) { VisibilityChecker vc = (VisibilityChecker) values.get("findAutoDetectVisibility"); // not really good but: @@ -391,12 +391,13 @@ public void testFindAutoDetectVisibility() throws Exception VisibilityChecker vc = VisibilityChecker.defaultInstance(); IntrospectorWithMap intr1 = new IntrospectorWithMap() .add("findAutoDetectVisibility", vc); + SerializationConfig config = null; assertNull(new AnnotationIntrospectorPair(NO_ANNOTATIONS, NO_ANNOTATIONS) - .findAutoDetectVisibility(null, null)); + .findAutoDetectVisibility(config, null, null)); assertSame(vc, new AnnotationIntrospectorPair(intr1, NO_ANNOTATIONS) - .findAutoDetectVisibility(null, null)); + .findAutoDetectVisibility(config, null, null)); assertSame(vc, new AnnotationIntrospectorPair(NO_ANNOTATIONS, intr1) - .findAutoDetectVisibility(null, null)); + .findAutoDetectVisibility(config, null, null)); } /*