Skip to content

Commit

Permalink
Further changes to #1133 fix, bit simpler, more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Feb 26, 2016
1 parent e1760c8 commit 9cf92cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,18 @@ public JavaType findBoundType(String name)
{
for (int i = 0, len = _names.length; i < len; ++i) {
if (name.equals(_names[i])) {
return _types[i];
JavaType t = _types[i];
if (t instanceof ResolvedRecursiveType) {
ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
JavaType t2 = rrt.getSelfReferencedType();
if (t2 == null) {
throw new IllegalStateException(String.format
("Unresolved ResolvedRecursiveType for parameter '%s' (index #%d; erased type %s)",
name, i, t.getRawClass()));
}
return t2;
}
return t;
}
}
return null;
Expand Down
52 changes: 5 additions & 47 deletions src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -560,29 +560,17 @@ public JavaType moreSpecificType(JavaType type1, JavaType type2)
*/

public JavaType constructType(Type type) {
JavaType t = _fromAny(null, type, EMPTY_BINDINGS);
if (t instanceof ResolvedRecursiveType) {
t = _resolveRecursive(t);
}
return t;
return _fromAny(null, type, EMPTY_BINDINGS);
}

public JavaType constructType(Type type, TypeBindings bindings) {
JavaType t = _fromAny(null, type, bindings);
if (t instanceof ResolvedRecursiveType) {
t = _resolveRecursive(t);
}
return t;
return _fromAny(null, type, bindings);
}

public JavaType constructType(TypeReference<?> typeRef)
{
// 19-Oct-2015, tatu: Simpler variant like so should work
JavaType t = _fromAny(null, typeRef.getType(), EMPTY_BINDINGS);
if (t instanceof ResolvedRecursiveType) {
t = _resolveRecursive(t);
}
return t;
return _fromAny(null, typeRef.getType(), EMPTY_BINDINGS);

// but if not, due to funky sub-classing, type variables, what follows
// is a more complete processing a la Java ClassMate.
Expand Down Expand Up @@ -610,11 +598,7 @@ public JavaType constructType(TypeReference<?> typeRef)
public JavaType constructType(Type type, Class<?> contextClass) {
TypeBindings bindings = (contextClass == null)
? TypeBindings.emptyBindings() : constructType(contextClass).getBindings();
JavaType t = _fromAny(null, type, bindings);
if (t instanceof ResolvedRecursiveType) {
t = _resolveRecursive(t);
}
return t;
return _fromAny(null, type, bindings);
}

/**
Expand All @@ -624,23 +608,9 @@ public JavaType constructType(Type type, Class<?> contextClass) {
public JavaType constructType(Type type, JavaType contextType) {
TypeBindings bindings = (contextType == null)
? TypeBindings.emptyBindings() : contextType.getBindings();
JavaType t = _fromAny(null, type, bindings);
if (t instanceof ResolvedRecursiveType) {
t = _resolveRecursive(t);
}
return t;
return _fromAny(null, type, bindings);
}

// since 2.7.2
private JavaType _resolveRecursive(JavaType t) {
ResolvedRecursiveType rrt = (ResolvedRecursiveType) t;
JavaType t2 = rrt.getSelfReferencedType();
if (t2 == null) { // should never occur, so sanity check
throw new IllegalStateException("Failed to resolve self-referential type "+t.getRawClass());
}
return t2;
}

/*
/**********************************************************
/* Direct factory methods
Expand Down Expand Up @@ -1139,18 +1109,6 @@ else if (type instanceof WildcardType) {
// sanity check
throw new IllegalArgumentException("Unrecognized Type: "+((type == null) ? "[null]" : type.toString()));
}
/*
if (resultType instanceof ResolvedRecursiveType) {
ResolvedRecursiveType rr = (ResolvedRecursiveType) resultType;
System.err.println("ResolvedRecursiveType["+type.getClass().getName()+"]\n..."+rr.getRawClass().getName()+" -> "+rr.getReferencedType());
try {
throw new Exception();
} catch (Exception e) {
System.err.println(" Stack: ");
e.printStackTrace();
}
}
*/
/* 21-Feb-2016, nateB/tatu: as per [databind#1129] (applied for 2.7.2),
* we do need to let all kinds of types to be refined, esp. for Scala module.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void testIssue1128() throws Exception
ObjectMapper mapper = new ObjectMapper();
// mapper.setSerializationInclusion(JsonInclude.Include.NON_DEFAULT);
mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

final DevMContainer devMContainer1 = new DevMContainer();
final DevM entity = new DevM();
final Dev parent = new Dev();
Expand All @@ -55,6 +55,8 @@ public void testIssue1128() throws Exception
devMContainer1.entity = entity;

String json = mapper.writeValueAsString(devMContainer1);
// String json = "{\"entity\":{\"id\":0,\"parent\":{\"id\":2,\"p1\":0},\"p1\":0,\"m1\":0}}";

System.out.println("serializedContainer = " + json);
final DevMContainer devMContainer = mapper.readValue(json, DevMContainer.class);
System.out.println("devMContainer.getEntity().getParent().getId() = " + devMContainer.entity.parent.id);
Expand Down

0 comments on commit 9cf92cc

Please sign in to comment.