@@ -75,13 +75,6 @@ public final class TypeFactory
75
75
76
76
private final static JavaType [] NO_TYPES = new JavaType [0 ];
77
77
78
- /**
79
- * Globally shared singleton. Not accessed directly; non-core
80
- * code should use per-ObjectMapper instance (via configuration objects).
81
- * Core Jackson code uses {@link #defaultInstance} for accessing it.
82
- */
83
- protected final static TypeFactory instance = new TypeFactory ();
84
-
85
78
protected final static TypeBindings EMPTY_BINDINGS = TypeBindings .emptyBindings ();
86
79
87
80
/*
@@ -161,7 +154,10 @@ public final class TypeFactory
161
154
protected final TypeModifier [] _modifiers ;
162
155
163
156
/**
164
- * ClassLoader used by this factory [databind#624].
157
+ * ClassLoader used by this factory.
158
+ *<p>
159
+ * See <a href="https://github.com/FasterXML/jackson-databind/issues/624">[databind#624]</a>
160
+ * for details.
165
161
*/
166
162
protected final ClassLoader _classLoader ;
167
163
@@ -171,8 +167,9 @@ public final class TypeFactory
171
167
/**********************************************************************
172
168
*/
173
169
174
- private TypeFactory () {
175
- this (new SimpleLookupCache <Object ,JavaType >(16 , DEFAULT_MAX_CACHE_SIZE ));
170
+ // NOTE: was private in Jackson 2.x
171
+ public TypeFactory () {
172
+ this (new SimpleLookupCache <>(16 , DEFAULT_MAX_CACHE_SIZE ));
176
173
}
177
174
178
175
protected TypeFactory (LookupCache <Object ,JavaType > typeCache ) {
@@ -187,6 +184,16 @@ protected TypeFactory(LookupCache<Object,JavaType> typeCache,
187
184
_classLoader = classLoader ;
188
185
}
189
186
187
+ /**
188
+ * Method used to construct a new default/standard {@code TypeFactory}
189
+ * instance; an instance which has
190
+ * no custom configuration. Used by {@code ObjectMapper} to
191
+ * get the default factory when constructed.
192
+ *
193
+ * @since 3.0
194
+ */
195
+ public static TypeFactory createDefaultInstance () { return new TypeFactory (); }
196
+
190
197
/**
191
198
* Need to make a copy on snapshot() to avoid accidental leakage via cache.
192
199
* In theory only needed if there are modifiers, but since these are lightweight
@@ -242,13 +249,6 @@ public TypeFactory withCache(LookupCache<Object,JavaType> cache) {
242
249
return new TypeFactory (cache , _modifiers , _classLoader );
243
250
}
244
251
245
- /**
246
- * Method used to access the globally shared instance, which has
247
- * no custom configuration. Used by <code>ObjectMapper</code> to
248
- * get the default factory when constructed.
249
- */
250
- public static TypeFactory defaultInstance () { return instance ; }
251
-
252
252
/**
253
253
* Method that will clear up any cached type definitions that may
254
254
* be cached by this {@link TypeFactory} instance.
@@ -306,6 +306,27 @@ public static Class<?> rawClass(Type t) {
306
306
+ClassUtil .classNameOf (t ));
307
307
}
308
308
309
+ // 12-Oct-2024, tatu: not ideal but has to do for now -- maybe can re-factor somehow
310
+ // before 3.0 release?
311
+ /**
312
+ * Method by core databind for constructing "simple" {@link JavaType}s in cases
313
+ * where there is no access to {@link TypeFactory} AND it is known that full
314
+ * resolution of the type is not needed (generally when type is just a placeholder).
315
+ * NOT TO BE USED by application code!
316
+ *
317
+ * @since 3.0
318
+ */
319
+ public static JavaType unsafeSimpleType (Class <?> cls ) {
320
+ // 18-Oct-2015, tatu: Not sure how much problem missing super-type info is here
321
+ // Copied from `_constructSimple()`:
322
+ JavaType t = _findWellKnownSimple (cls );
323
+ if (t == null ) {
324
+ // copied from `_newSimpleType()`
325
+ return new SimpleType (cls , EMPTY_BINDINGS , null , null );
326
+ }
327
+ return t ;
328
+ }
329
+
309
330
/*
310
331
/**********************************************************************
311
332
/* Low-level helper methods
@@ -748,22 +769,15 @@ public JavaType constructType(TypeReference<?> typeRef)
748
769
*
749
770
* @param type Type of a {@link java.lang.reflect.Member} to resolve
750
771
* @param contextBindings Type bindings from the context, often class in which
751
- * member declared but may be subtype of that type (to bind actual bound
752
- * type parametrers ). Not used if {@code type} is of type {@code Class<?>}.
772
+ * member declared but may be sub-type of that type (to bind actual bound
773
+ * type parameters ). Not used if {@code type} is of type {@code Class<?>}.
753
774
*
754
775
* @return Fully resolved type
755
776
*/
756
777
public JavaType resolveMemberType (Type type , TypeBindings contextBindings ) {
757
778
return _fromAny (null , type , contextBindings );
758
779
}
759
780
760
- // 20-Apr-2018, tatu: Really should get rid of this...
761
- @ Deprecated // since 2.8
762
- public JavaType uncheckedSimpleType (Class <?> cls ) {
763
- // 18-Oct-2015, tatu: Not sure how much problem missing super-type info is here
764
- return _constructSimple (cls , EMPTY_BINDINGS , null , null );
765
- }
766
-
767
781
/*
768
782
/**********************************************************************
769
783
/* Direct factory methods
@@ -1221,7 +1235,7 @@ protected JavaType _unknownType() {
1221
1235
* type is one of common, "well-known" types, instances of which are
1222
1236
* pre-constructed and do not need dynamic caching.
1223
1237
*/
1224
- protected JavaType _findWellKnownSimple (Class <?> clz ) {
1238
+ protected static JavaType _findWellKnownSimple (Class <?> clz ) {
1225
1239
if (clz .isPrimitive ()) {
1226
1240
if (clz == CLS_BOOL ) return CORE_TYPE_BOOL ;
1227
1241
if (clz == CLS_INT ) return CORE_TYPE_INT ;
0 commit comments