Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 2, 2015
1 parent 16ba95f commit 1b68756
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 101 deletions.
Expand Up @@ -1039,7 +1039,8 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,
final Annotated a, final JavaType baseType) throws JsonMappingException
{
JavaType type = baseType;

final TypeFactory tf = config.getTypeFactory();

// 10-Oct-2015, tatu: For 2.7, we'll need to delegate back to
// now-deprecated secondary methods; this because while
// direct sub-class not yet retrofitted may only override
Expand All @@ -1048,14 +1049,14 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,


// Ok: start by refining the main type itself; common to all types
Class<?> contentClass = findDeserializationType(a, type);
if ((contentClass != null) && !type.hasRawClass(contentClass)) {
Class<?> valueClass = findDeserializationType(a, type);
if ((valueClass != null) && !type.hasRawClass(valueClass)) {
try {
type = config.getTypeFactory().constructSpecializedType(type, contentClass);
type = tf.constructSpecializedType(type, valueClass);
} catch (IllegalArgumentException iae) {
throw new JsonMappingException(null,
String.format("Failed to narrow type %s with annotation (value %s), from '%s': %s",
type, contentClass.getName(), a.getName(), iae.getMessage()),
type, valueClass.getName(), a.getName(), iae.getMessage()),
iae);
}
}
Expand All @@ -1075,16 +1076,18 @@ public JavaType refineDeserializationType(final MapperConfig<?> config,
}
}
}
if (type.getContentType() != null) { // collection[like], map[like], array, reference
JavaType contentType = type.getContentType();
if (contentType != null) { // collection[like], map[like], array, reference
// And then value types for all containers:
Class<?> valueClass = findDeserializationContentType(a, type.getContentType());
if (valueClass != null) {
Class<?> contentClass = findDeserializationContentType(a, type.getContentType());
if (contentClass != null) {
try {
type = type.narrowContentsBy(valueClass);
contentType = tf.constructSpecializedType(contentType, contentClass);
type = type.withContentType(contentType);
} catch (IllegalArgumentException iae) {
throw new JsonMappingException(null,
String.format("Failed to narrow value type of %s with concrete-type annotation (value %s), from '%s': %s",
type, valueClass.getName(), a.getName(), iae.getMessage()),
type, contentClass.getName(), a.getName(), iae.getMessage()),
iae);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/fasterxml/jackson/databind/JavaType.java
Expand Up @@ -210,8 +210,6 @@ public JavaType forcedNarrowBy(Class<?> subclass)

protected abstract JavaType _narrow(Class<?> subclass);

public abstract JavaType narrowContentsBy(Class<?> contentClass);

/**
* Mutant factory method that will try to create and return a sub-type instance
* for known parameterized types; for other types will return `null` to indicate
Expand Down
Expand Up @@ -82,6 +82,7 @@ protected TypeDeserializerBase(JavaType baseType, TypeIdResolver idRes,
* not entirely safe... however, since Collections/Maps are
* seldom (if ever) base types, may be ok.
*/
// 01-Nov-2015, tatu: Actually this is still exactly wrong. Should fix.
_defaultImpl = baseType.forcedNarrowBy(defaultImpl);
}
_property = null;
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/fasterxml/jackson/databind/type/ArrayType.java
Expand Up @@ -115,19 +115,6 @@ protected JavaType _narrow(Class<?> subclass) {
return _reportUnsupported();
}

/**
* For array types, both main type and content type can be modified;
* but ultimately they are interchangeable.
*/
@Override
public JavaType narrowContentsBy(Class<?> contentClass) {
if (contentClass == _componentType.getRawClass()) {
return this;
}
return construct(_componentType.narrowBy(contentClass), _bindings,
_valueHandler, _typeHandler);
}

// Should not be called, as array types in Java are not extensible; but
// let's not freak out even if it is called?
@Override
Expand Down
Expand Up @@ -78,18 +78,6 @@ protected JavaType _narrow(Class<?> subclass) {
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionLikeType(_class, _bindings,
_superClass, _superInterfaces, _elementType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType withContentType(JavaType contentType) {
if (_elementType == contentType) {
Expand Down
Expand Up @@ -58,18 +58,6 @@ protected JavaType _narrow(Class<?> subclass) {
_superClass, _superInterfaces, _elementType, null, null, _asStatic);
}

@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _elementType.getRawClass()) {
return this;
}
return new CollectionType(_class, _bindings,
_superClass, _superInterfaces, _elementType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType withContentType(JavaType contentType) {
if (_elementType == contentType) {
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/fasterxml/jackson/databind/type/MapLikeType.java
Expand Up @@ -78,18 +78,6 @@ protected JavaType _narrow(Class<?> subclass) {
_superClass, _superInterfaces, _keyType, _valueType, _valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapLikeType(_class, _bindings,
_superClass, _superInterfaces, _keyType, _valueType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}

public JavaType narrowKey(Class<?> keySubclass)
{
// Can do a quick check first:
Expand Down
12 changes: 0 additions & 12 deletions src/main/java/com/fasterxml/jackson/databind/type/MapType.java
Expand Up @@ -51,18 +51,6 @@ protected JavaType _narrow(Class<?> subclass) {
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (contentClass == _valueType.getRawClass()) {
return this;
}
return new MapType(_class, _bindings,
_superClass, _superInterfaces, _keyType, _valueType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType narrowKey(Class<?> keySubclass)
{
Expand Down
Expand Up @@ -67,7 +67,16 @@ public static ReferenceType construct(Class<?> cls, JavaType refType) {
return new ReferenceType(cls, TypeBindings.emptyBindings(),
// !!! TODO: missing supertypes
null, null, refType, null, null, false);
}
}

@Override
public JavaType withContentType(JavaType contentType) {
if (_referencedType == contentType) {
return this;
}
return new ReferenceType(_class, _bindings, _superClass, _superInterfaces,
contentType, _valueHandler, _typeHandler, _asStatic);
}

@Override
public ReferenceType withTypeHandler(Object h)
Expand Down Expand Up @@ -152,21 +161,6 @@ protected JavaType _narrow(Class<?> subclass)
_valueHandler, _typeHandler, _asStatic);
}

// no need to override _widen() since it by default just calls _narrow() anyway
// protected JavaType _widen(Class<?> subclass)

@Override
public JavaType narrowContentsBy(Class<?> contentClass)
{
// Can do a quick check first:
if (_referencedType.hasRawClass(contentClass)) {
return this;
}
return new ReferenceType(_class, _bindings,
_superClass, _superInterfaces, _referencedType.narrowBy(contentClass),
_valueHandler, _typeHandler, _asStatic);
}

/*
/**********************************************************
/* Public API overrides
Expand Down
Expand Up @@ -73,11 +73,6 @@ protected JavaType _narrow(Class<?> subclass) {
return this;
}

@Override
public JavaType narrowContentsBy(Class<?> contentClass) {
return this;
}

@Override
public JavaType refine(Class<?> rawType, TypeBindings bindings,
JavaType superClass, JavaType[] superInterfaces) {
Expand Down
Expand Up @@ -84,13 +84,6 @@ protected JavaType _narrow(Class<?> subclass)
_valueHandler, _typeHandler, _asStatic);
}

@Override
public JavaType narrowContentsBy(Class<?> subclass)
{
// should never get called
throw new IllegalArgumentException("Internal error: SimpleType.narrowContentsBy() should never be called");
}

public static SimpleType construct(Class<?> cls)
{
/* Let's add sanity checks, just to ensure no
Expand Down

0 comments on commit 1b68756

Please sign in to comment.