From 4a401237adfe3fd4e417504176171f76464aae96 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Sat, 12 Oct 2024 23:23:21 -0700 Subject: [PATCH] Add `TypeFactory.createDefaultInstance()` --- .../jackson/databind/type/TypeFactory.java | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java b/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java index 6df8f9f254..5173b9ddf0 100644 --- a/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/type/TypeFactory.java @@ -1,11 +1,6 @@ package com.fasterxml.jackson.databind.type; -import java.lang.reflect.Array; -import java.lang.reflect.GenericArrayType; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; +import java.lang.reflect.*; import java.util.*; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.BaseStream; @@ -18,10 +13,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.util.ArrayBuilders; -import com.fasterxml.jackson.databind.util.ClassUtil; -import com.fasterxml.jackson.databind.util.LRUMap; -import com.fasterxml.jackson.databind.util.LookupCache; +import com.fasterxml.jackson.databind.util.*; /** * Class used for creating concrete {@link JavaType} instances, @@ -70,7 +62,6 @@ * * */ -@SuppressWarnings({"rawtypes" }) public class TypeFactory // note: was final in 2.9, removed from 2.10 implements java.io.Serializable { @@ -79,8 +70,6 @@ public class TypeFactory // note: was final in 2.9, removed from 2.10 /** * Default size used to construct {@link #_typeCache}. * - * Used to be passed inline. - * * @since 2.16 */ public static final int DEFAULT_MAX_CACHE_SIZE = 200; @@ -222,6 +211,14 @@ protected TypeFactory(LookupCache typeCache, TypeParser p, _classLoader = classLoader; } + /** + * Method used to construct a new default/standard {@code TypeFactory} + * instance; an instance which has no custom configuration. + * + * @since 2.19 + */ + public static TypeFactory createDefaultInstance() { return new TypeFactory(); } + /** * "Mutant factory" method which will construct a new instance with specified * {@link TypeModifier} added as the first modifier to call (in case there @@ -923,6 +920,7 @@ public ArrayType constructArrayType(JavaType elementType) { * NOTE: type modifiers are NOT called on Collection type itself; but are called * for contained types. */ + @SuppressWarnings({"rawtypes" }) public CollectionType constructCollectionType(Class collectionClass, Class elementClass) { return constructCollectionType(collectionClass, @@ -935,6 +933,7 @@ public CollectionType constructCollectionType(Class collec * NOTE: type modifiers are NOT called on Collection type itself; but are called * for contained types. */ + @SuppressWarnings({"rawtypes" }) public CollectionType constructCollectionType(Class collectionClass, JavaType elementType) { @@ -986,6 +985,7 @@ public CollectionLikeType constructCollectionLikeType(Class collectionClass, * NOTE: type modifiers are NOT called on constructed type itself; but are called * for contained types. */ + @SuppressWarnings({"rawtypes" }) public MapType constructMapType(Class mapClass, Class keyClass, Class valueClass) { JavaType kt, vt; @@ -1003,6 +1003,7 @@ public MapType constructMapType(Class mapClass, *

* NOTE: type modifiers are NOT called on constructed type itself. */ + @SuppressWarnings({"rawtypes" }) public MapType constructMapType(Class mapClass, JavaType keyType, JavaType valueType) { TypeBindings bindings = TypeBindings.createIfNeeded(mapClass, new JavaType[] { keyType, valueType }); MapType result = (MapType) _fromClass(null, mapClass, bindings); @@ -1232,6 +1233,7 @@ public JavaType constructParametrizedType(Class parametrized, Class parame *

* This method should only be used if parameterization is completely unavailable. */ + @SuppressWarnings({"rawtypes" }) public CollectionType constructRawCollectionType(Class collectionClass) { return constructCollectionType(collectionClass, unknownType()); } @@ -1262,6 +1264,7 @@ public CollectionLikeType constructRawCollectionLikeType(Class collectionClas *

* This method should only be used if parameterization is completely unavailable. */ + @SuppressWarnings({"rawtypes" }) public MapType constructRawMapType(Class mapClass) { return constructMapType(mapClass, unknownType(), unknownType()); }