Skip to content

Commit

Permalink
Fix FasterXML#894 - derived TypeFactory (instantiated using with... m…
Browse files Browse the repository at this point in the history
…ethod) should have a new TypeParser which points to itself
  • Loading branch information
lufe committed Aug 12, 2015
1 parent 28d3eb0 commit bf54c00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public final class TypeFactory
*/
protected final TypeModifier[] _modifiers;

protected final TypeParser _parser;
protected TypeParser _parser;

/**
* ClassLoader used by this factory (Issue #624)
Expand Down Expand Up @@ -129,16 +129,16 @@ protected TypeFactory(TypeParser p, TypeModifier[] mods, ClassLoader classLoader
public TypeFactory withModifier(TypeModifier mod)
{
if (mod == null) { // mostly for unit tests
return new TypeFactory(_parser, _modifiers, _classLoader);
return factoryWithModifiedParser(_parser, _modifiers, _classLoader);
}
if (_modifiers == null) {
return new TypeFactory(_parser, new TypeModifier[] { mod }, _classLoader);
return factoryWithModifiedParser(_parser, new TypeModifier[] { mod }, _classLoader);
}
return new TypeFactory(_parser, ArrayBuilders.insertInListNoDup(_modifiers, mod), _classLoader);
return factoryWithModifiedParser(_parser, ArrayBuilders.insertInListNoDup(_modifiers, mod), _classLoader);
}

public TypeFactory withClassLoader(ClassLoader classLoader) {
return new TypeFactory(_parser, _modifiers, classLoader);
return factoryWithModifiedParser(_parser, _modifiers, classLoader);
}

/**
Expand Down Expand Up @@ -1283,4 +1283,14 @@ protected synchronized HierarchicType _arrayListSuperInterfaceChain(HierarchicTy
t.setSubType(current);
return current;
}

private void setTypeParser(TypeParser p) {
this._parser = p;
}

private TypeFactory factoryWithModifiedParser(TypeParser p, TypeModifier[] mods, ClassLoader classLoader) {
TypeFactory f = new TypeFactory(p, mods, classLoader);
f.setTypeParser(p.withFactory(f));
return f;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public TypeParser(TypeFactory f) {
_factory = f;
}

public TypeParser withFactory(TypeFactory f) {
return new TypeParser(f);
}

public JavaType parse(String canonical)
throws IllegalArgumentException
{
Expand Down

0 comments on commit bf54c00

Please sign in to comment.