Skip to content

Commit

Permalink
Refactoring to prepare for fixing #312
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 26, 2015
1 parent 9a233d9 commit 9039a9b
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ public TypeDeserializer findTypeDeserializer(JavaType baseType)
return null;
}
} else {
subtypes = getSubtypeResolver().collectAndResolveSubtypes(ac, this, getAnnotationIntrospector());
subtypes = getSubtypeResolver().collectAndResolveSubtypesByName(this, ac);
}
/* 04-May-2014, tatu: When called from DeserializerFactory, additional code like
* this is invoked. But here we do not actually have access to mappings, so not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ public TypeDeserializer findTypeDeserializer(DeserializationConfig config,
return null;
}
} else {
subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(ac, config, ai);
subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByName(config, ac);
}
// [JACKSON-505]: May need to figure out default implementation, if none found yet
// (note: check for abstract type is not 100% mandatory, more of an optimization)
Expand Down Expand Up @@ -1356,7 +1356,7 @@ private KeyDeserializer _createEnumKeyDeserializer(DeserializationContext ctxt,
// [JACKSON-749] Also, need to consider @JsonValue, if one found
return StdKeyDeserializers.constructEnumKeyDeserializer(enumRes);
}

/*
/**********************************************************
/* Extended API
Expand Down Expand Up @@ -1387,8 +1387,8 @@ public TypeDeserializer findPropertyTypeDeserializer(DeserializationConfig confi
return findTypeDeserializer(config, baseType);
}
// but if annotations found, may need to resolve subtypes:
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(
annotated, config, ai, baseType);
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByName(
config, annotated, baseType);
return b.buildTypeDeserializer(config, baseType, subtypes);
}

Expand All @@ -1415,8 +1415,8 @@ public TypeDeserializer findPropertyContentTypeDeserializer(DeserializationConfi
return findTypeDeserializer(config, contentType);
}
// but if annotations found, may need to resolve subtypes:
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(
propertyEntity, config, ai, contentType);
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByName(
config, propertyEntity, contentType);
return b.buildTypeDeserializer(config, contentType, subtypes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
*/
public abstract class SubtypeResolver
{
/*
/**********************************************************
/* Methods for registering external subtype definitions
/**********************************************************
*/

/**
* Method for registering specified subtypes (possibly including type
* names); for type entries without name, non-qualified class name
Expand All @@ -23,22 +29,107 @@ public abstract class SubtypeResolver

public abstract void registerSubtypes(Class<?>... classes);

/*
/**********************************************************
/* Subtype resolution
/**********************************************************
*/

/**
* Method for finding out all reachable subtypes for a property specified
* by given element (method or field),
* such that access is by type,
* typically needed for serialization (converting from type to type name).
*
* @param baseType Effective property base type to use; may differ from
* actual type of property; for structured types it is content (value) type and NOT
* structured type.
*
* @since 2.6
*/
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config,
AnnotatedMember property, JavaType baseType) {
// for backwards compatibility...
return collectAndResolveSubtypes(property, config,
config.getAnnotationIntrospector(), baseType);
}

/**
* Method for finding out all reachable subtypes for given type,
* such that access is by type,
* typically needed for serialization (converting from type to type name).
*
* @param baseType Effective property base type to use; may differ from
* actual type of property; for structured types it is content (value) type and NOT
* structured type.
*
* @since 2.6
*/
public Collection<NamedType> collectAndResolveSubtypesByClass(MapperConfig<?> config,
AnnotatedClass baseType) {
// for backwards compatibility...
return collectAndResolveSubtypes(baseType, config, config.getAnnotationIntrospector());
}

/**
* Method for finding out all reachable subtypes for a property specified
* by given element (method or field)
* by given element (method or field),
* such that access is by type id,
* typically needed for deserialization (converting from type id to type).
*
* @param baseType Effective property base type to use; may differ from
* actual type of property; for structured types it is content (value) type and NOT
* structured type.
*
* @since 2.1
* @since 2.6
*/
public Collection<NamedType> collectAndResolveSubtypesByName(MapperConfig<?> config,
AnnotatedMember property, JavaType baseType) {
// for backwards compatibility...
return collectAndResolveSubtypes(property, config,
config.getAnnotationIntrospector(), baseType);
}

/**
* Method for finding out all reachable subtypes for given type,
* such that access is by type id,
* typically needed for deserialization (converting from type id to type).
*
* @param baseType Effective property base type to use; may differ from
* actual type of property; for structured types it is content (value) type and NOT
* structured type.
*
* @since 2.6
*/
public Collection<NamedType> collectAndResolveSubtypesByName(MapperConfig<?> config,
AnnotatedClass baseType) {
// for backwards compatibility...
return collectAndResolveSubtypes(baseType, config, config.getAnnotationIntrospector());
}

/*
/**********************************************************
/* Deprecated methods
/**********************************************************
*/

/**
* @deprecated Since 2.6 Use either
* {@link #collectAndResolveSubtypesByClass(MapperConfig, AnnotatedMember, JavaType)}
* or {@link #collectAndResolveSubtypesByName(MapperConfig, AnnotatedMember, JavaType)}
* instead.
*/
@Deprecated
public abstract Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember property,
MapperConfig<?> config, AnnotationIntrospector ai, JavaType baseType);

/**
* Method for finding out all reachable subtypes for given type.
* @deprecated Since 2.6 Use either
* {@link #collectAndResolveSubtypesByClass(MapperConfig, AnnotatedClass)}
* or {@link #collectAndResolveSubtypesByName(MapperConfig, AnnotatedClass)}
* instead.
*/
public abstract Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass basetype,
@Deprecated
public abstract Collection<NamedType> collectAndResolveSubtypes(AnnotatedClass baseType,
MapperConfig<?> config, AnnotationIntrospector ai);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public void registerSubtypes(Class<?>... classes) {
}

/**
*
* @param property Base member to use for type resolution: either annotated type (class),
* or property (field, getter/setter)
*
* @since 2.1
* @deprecated Since 2.6
*/
@Override
public Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember property,
Expand Down Expand Up @@ -87,6 +83,7 @@ public Collection<NamedType> collectAndResolveSubtypes(AnnotatedMember property,

// and finally subtypes via annotations from base type (recursively)
_collectAndResolve(ac, rootType, config, ai, collected);

return new ArrayList<NamedType>(collected.values());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public TypeSerializer createTypeSerializer(SerializationConfig config,
if (b == null) {
b = config.getDefaultTyper(baseType);
} else {
subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(ac, config, ai);
subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config, ac);
}
if (b == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ public TypeSerializer findPropertyTypeSerializer(JavaType baseType,
if (b == null) {
return createTypeSerializer(config, baseType);
}
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(
accessor, config, ai, baseType);
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(
config, accessor, baseType);
return b.buildTypeSerializer(config, baseType, subtypes);
}

Expand All @@ -315,8 +315,8 @@ public TypeSerializer findPropertyContentTypeSerializer(JavaType containerType,
if (b == null) {
return createTypeSerializer(config, contentType);
}
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypes(accessor,
config, ai, contentType);
Collection<NamedType> subtypes = config.getSubtypeResolver().collectAndResolveSubtypesByClass(config,
accessor, contentType);
return b.buildTypeSerializer(config, contentType, subtypes);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.*;

public class TestOverlappingTypeIdNames312 extends BaseMapTest
Expand Down

0 comments on commit 9039a9b

Please sign in to comment.