Skip to content

Commit

Permalink
Fix #1301
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 18, 2016
1 parent f6fbed5 commit c62d8c7
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 5 deletions.
4 changes: 4 additions & 0 deletions release-notes/CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,7 @@ Andrew Joseph (apjoseph@github)
Erich Schubert (kno10@github)
* Reported #1260: `NullPointerException` in `JsonNodeDeserializer`, provided fix
(2.7.5)

Brian Pontarelli (voidmain@github)
* Reported #1301: Problem with `JavaType.toString()` for recursive (self-referential) types
(2.7.6)
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Project: jackson-databind
(reported by brentryan@github)
#1279: Ensure DOM parsing defaults to not expanding external entities
#1288: Type id not exposed for `JsonTypeInfo.As.EXTERNAL_PROPERTY` even when `visible` set to `true`
#1301: Problem with `JavaType.toString()` for recursive (self-referential) types
(reported by Brian P)

2.7.5 (11-Jun-2016)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,16 @@ public boolean isContainerType() {

@Override
public String toString() {
return new StringBuilder(40)
.append("[resolved recursive type -> ")
.append(_referencedType)
.append(']')
.toString();
StringBuilder sb = new StringBuilder(40)
.append("[recursive type; ");
if (_referencedType == null) {
sb.append("UNRESOLVED");
} else {
// [databind#1301]: Typically resolves to a loop so short-cut
// and only include type-erased class
sb.append(_referencedType.getRawClass().getName());
}
return sb.toString();
}

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

import java.util.HashMap;

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.type.TypeFactory;

@SuppressWarnings("serial")
public class JavaTypeDesc1301Test extends BaseMapTest
{
static class DataDefinition extends HashMap<String, DataDefinition> {
public DataDefinition definition;
public DataDefinition elements;
public String regex;
public boolean required;
public String type;
}

// for [databind#1301]
public void testJavaTypeToString() throws Exception
{
TypeFactory tf = objectMapper().getTypeFactory();
String desc = tf.constructType(DataDefinition.class).toString();
assertNotNull(desc);
// could try comparing exact message, but since it's informational try looser:
if (!desc.contains("map type")) {
fail("Description should contain 'map type', did not: "+desc);
}
if (!desc.contains("recursive type")) {
fail("Description should contain 'recursive type', did not: "+desc);
}
}
}

0 comments on commit c62d8c7

Please sign in to comment.