Skip to content

Commit

Permalink
Fix #1125
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Mar 9, 2016
1 parent a290f09 commit 700617a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Expand Up @@ -6,6 +6,7 @@ Project: jackson-databind

2.7.3 (not yet released)

#1125: Problem with polymorphic types, losing properties from base type(s)
#1150: Problem with Object id handling, explicit `null` token
(reported by Xavi T)

Expand Down
39 changes: 33 additions & 6 deletions src/main/java/com/fasterxml/jackson/databind/type/SimpleType.java
Expand Up @@ -127,16 +127,43 @@ protected JavaType _narrow(Class<?> subclass)
}
// Should we check that there is a sub-class relationship?
// 15-Jan-2016, tatu: Almost yes, but there are some complications with
// placeholder values, so no.
/*
// placeholder values (`Void`, `NoClass`), so can not quite do yet.
// TODO: fix in 2.8
if (!_class.isAssignableFrom(subclass)) {
/*
throw new IllegalArgumentException("Class "+subclass.getName()+" not sub-type of "
+_class.getName());
*/
return new SimpleType(subclass, _bindings, this, _superInterfaces,
_valueHandler, _typeHandler, _asStatic);
}
*/
// 15-Jan-2015, tatu: Not correct; should really re-resolve...
return new SimpleType(subclass, _bindings, this, _superInterfaces,
_valueHandler, _typeHandler, _asStatic);
// Otherwise, stitch together the hierarchy. First, super-class
Class<?> next = subclass.getSuperclass();
if (next == _class) { // straight up parent class? Great.
return new SimpleType(subclass, _bindings, this,
_superInterfaces, _valueHandler, _typeHandler, _asStatic);
}
if ((next != null) && _class.isAssignableFrom(next)) {
JavaType superb = _narrow(next);
return new SimpleType(subclass, _bindings, superb,
null, _valueHandler, _typeHandler, _asStatic);
}
// if not found, try a super-interface
Class<?>[] nextI = subclass.getInterfaces();
for (Class<?> iface : nextI) {
if (iface == _class) { // directly implemented
return new SimpleType(subclass, _bindings, null,
new JavaType[] { this }, _valueHandler, _typeHandler, _asStatic);
}
if (_class.isAssignableFrom(iface)) { // indirect, so recurse
JavaType superb = _narrow(iface);
return new SimpleType(subclass, _bindings, null,
new JavaType[] { superb }, _valueHandler, _typeHandler, _asStatic);
}
}
// should not get here but...
throw new IllegalArgumentException("Internal error: Can not resolve sub-type for Class "+subclass.getName()+" to "
+_class.getName());
}

@Override
Expand Down
Expand Up @@ -160,7 +160,7 @@ public void testDeserializationWithArrayOfSize2() throws Exception
assertEquals(Arrays.asList("a", "b"), ((MyInter) inter).blah);
}

// [Databind#148]
// [databind#148]
public void testDefaultAsNoClass() throws Exception
{
Object ob = MAPPER.readerFor(DefaultWithNoClass.class).readValue("{ }");
Expand All @@ -178,7 +178,7 @@ public void testDefaultAsVoid() throws Exception
assertNull(ob);
}

// [Databind#148]
// [databind#148]
public void testBadTypeAsNull() throws Exception
{
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -189,7 +189,7 @@ public void testBadTypeAsNull() throws Exception
assertNull(ob);
}

// [Databind#511]
// [databind#511]
public void testInvalidTypeId511() throws Exception {
ObjectReader reader = MAPPER.reader().without(
DeserializationFeature.FAIL_ON_INVALID_SUBTYPE,
Expand All @@ -203,7 +203,7 @@ public void testInvalidTypeId511() throws Exception {
assertNotNull(badResult);
}

// [Databind#656]
// [databind#656]
public void testDefaultImplWithObjectWrapper() throws Exception
{
BaseFor656 value = MAPPER.readValue(aposToQuotes("{'foobar':{'a':3}}"), BaseFor656.class);
Expand Down

0 comments on commit 700617a

Please sign in to comment.