Skip to content

Commit

Permalink
Add passing of MapperConfig for more methods in `AnnotationIntrospe…
Browse files Browse the repository at this point in the history
…ctor`
  • Loading branch information
cowtowncoder committed Mar 16, 2018
1 parent db69efd commit f350b20
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
*<p>
* NOTE: method signature changed in 2.1, to return {@link PropertyName}
* instead of String.
*/
public PropertyName findRootName(AnnotatedClass ac) {
return null;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ 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;
SettableBeanProperty idProp = null;
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/*
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ public Set<String> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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));
}

/*
Expand Down

0 comments on commit f350b20

Please sign in to comment.