Skip to content

Commit bf54c00

Browse files
author
lufe
committed
Fix FasterXML#894 - derived TypeFactory (instantiated using with... method) should have a new TypeParser which points to itself
1 parent 28d3eb0 commit bf54c00

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public final class TypeFactory
9797
*/
9898
protected final TypeModifier[] _modifiers;
9999

100-
protected final TypeParser _parser;
100+
protected TypeParser _parser;
101101

102102
/**
103103
* ClassLoader used by this factory (Issue #624)
@@ -129,16 +129,16 @@ protected TypeFactory(TypeParser p, TypeModifier[] mods, ClassLoader classLoader
129129
public TypeFactory withModifier(TypeModifier mod)
130130
{
131131
if (mod == null) { // mostly for unit tests
132-
return new TypeFactory(_parser, _modifiers, _classLoader);
132+
return factoryWithModifiedParser(_parser, _modifiers, _classLoader);
133133
}
134134
if (_modifiers == null) {
135-
return new TypeFactory(_parser, new TypeModifier[] { mod }, _classLoader);
135+
return factoryWithModifiedParser(_parser, new TypeModifier[] { mod }, _classLoader);
136136
}
137-
return new TypeFactory(_parser, ArrayBuilders.insertInListNoDup(_modifiers, mod), _classLoader);
137+
return factoryWithModifiedParser(_parser, ArrayBuilders.insertInListNoDup(_modifiers, mod), _classLoader);
138138
}
139139

140140
public TypeFactory withClassLoader(ClassLoader classLoader) {
141-
return new TypeFactory(_parser, _modifiers, classLoader);
141+
return factoryWithModifiedParser(_parser, _modifiers, classLoader);
142142
}
143143

144144
/**
@@ -1283,4 +1283,14 @@ protected synchronized HierarchicType _arrayListSuperInterfaceChain(HierarchicTy
12831283
t.setSubType(current);
12841284
return current;
12851285
}
1286+
1287+
private void setTypeParser(TypeParser p) {
1288+
this._parser = p;
1289+
}
1290+
1291+
private TypeFactory factoryWithModifiedParser(TypeParser p, TypeModifier[] mods, ClassLoader classLoader) {
1292+
TypeFactory f = new TypeFactory(p, mods, classLoader);
1293+
f.setTypeParser(p.withFactory(f));
1294+
return f;
1295+
}
12861296
}

src/main/java/com/fasterxml/jackson/databind/type/TypeParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public TypeParser(TypeFactory f) {
2121
_factory = f;
2222
}
2323

24+
public TypeParser withFactory(TypeFactory f) {
25+
return new TypeParser(f);
26+
}
27+
2428
public JavaType parse(String canonical)
2529
throws IllegalArgumentException
2630
{

0 commit comments

Comments
 (0)