Package com.alibaba.fastjson.util
Class TypeUtils
- java.lang.Object
-
- com.alibaba.fastjson.util.TypeUtils
-
public class TypeUtils extends Object
- Author:
- wenshao[szujobs@hotmail.com]
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeUtils.MethodInheritanceComparator
-
Field Summary
Fields Modifier and Type Field Description static Function<Object,Object>castToTimestampFunctionstatic booleancompatibleWithFieldName根据field name的大小写输出输入数据static booleancompatibleWithJavaBeanstatic longfnv1a_64_magic_hashcodestatic longfnv1a_64_magic_prime
-
Constructor Summary
Constructors Constructor Description TypeUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static voidaddMapping(String className, Class<?> clazz)static SerializeBeanInfobuildBeanInfo(Class<?> beanType, Map<String,String> aliasMap, PropertyNamingStrategy propertyNamingStrategy)static SerializeBeanInfobuildBeanInfo(Class<?> beanType, Map<String,String> aliasMap, PropertyNamingStrategy propertyNamingStrategy, boolean fieldBased)static bytebyteValue(BigDecimal decimal)static <T> Tcast(Object obj, Class<T> clazz, ParserConfig config)static <T> Tcast(Object obj, ParameterizedType type, ParserConfig mapping)static <T> Tcast(Object obj, Type type, ParserConfig mapping)static BigDecimalcastToBigDecimal(Object value)static BigIntegercastToBigInteger(Object value)static BooleancastToBoolean(Object value)static BytecastToByte(Object value)static byte[]castToBytes(Object value)static CharactercastToChar(Object value)static DatecastToDate(Object value)static DatecastToDate(Object value, String format)static DoublecastToDouble(Object value)static <T> TcastToEnum(Object obj, Class<T> clazz, ParserConfig mapping)static FloatcastToFloat(Object value)static IntegercastToInt(Object value)static <T> TcastToJavaBean(Object obj, Class<T> clazz)static <T> TcastToJavaBean(Map<String,Object> map, Class<T> clazz, ParserConfig config)static LongcastToLong(Object value)static ShortcastToShort(Object value)static ObjectcastToSqlDate(Object value)static ObjectcastToSqlTime(Object value)static StringcastToString(Object value)static ObjectcastToTimestamp(Object value)static TypecheckPrimitiveArray(GenericArrayType genericArrayType)static voidclearClassMapping()static List<FieldInfo>computeGetters(Class<?> clazz, JSONType jsonType, Map<String,String> aliasMap, Map<String,Field> fieldCacheMap, boolean sorted, PropertyNamingStrategy propertyNamingStrategy)static List<FieldInfo>computeGetters(Class<?> clazz, Map<String,String> aliasMap)static List<FieldInfo>computeGetters(Class<?> clazz, Map<String,String> aliasMap, boolean sorted)static List<FieldInfo>computeGettersWithFieldBase(Class<?> clazz, Map<String,String> aliasMap, boolean sorted, PropertyNamingStrategy propertyNamingStrategy)static CollectioncreateCollection(Type type)static SetcreateSet(Type type)static Stringdecapitalize(String name)static longfnv1a_64(String key)static longfnv1a_64_extract(String key)static longfnv1a_64_lower(String key)static <A extends Annotation>
AgetAnnotation(Class<?> targetClass, Class<A> annotationClass)static <A extends Annotation>
AgetAnnotation(Field field, Class<A> annotationClass)static <A extends Annotation>
AgetAnnotation(Method method, Class<A> annotationClass)static Class<?>getClass(Type type)static Class<?>getClassFromMapping(String className)static Class<?>getCollectionItemClass(Type fieldType)static TypegetCollectionItemType(Type fieldType)static FieldgetField(Class<?> clazz, String fieldName, Field[] declaredFields)static TypegetGenericParamType(Type type)static String[]getKoltinConstructorParameters(Class clazz)static ConstructorgetKotlinConstructor(Constructor[] constructors)static ConstructorgetKotlinConstructor(Constructor[] constructors, String[] paramNames)static Annotation[][]getParameterAnnotations(Constructor constructor)static Annotation[][]getParameterAnnotations(Method method)static intgetParserFeatures(Class<?> clazz)static StringgetPropertyNameByMethodName(String methodName)resolve property name from get/set method namestatic Class<?>getRawClass(Type type)static intgetSerializeFeatures(Class<?> clazz)Deprecated.static JSONFieldgetSuperMethodAnnotation(Class<?> clazz, Method method)static AnnotationgetXmlAccessorType(Class clazz)static booleanhasIllegalTypeNameChars(String typeName)Tests whether a type name carries a character that cannot appear in a Java binary class name but is meaningful in a URL.static intintValue(BigDecimal decimal)static booleanisAnnotationPresentManyToMany(Method method)static booleanisAnnotationPresentOneToMany(Method method)static booleanisAutoTypeDenyClass(Class<?> type)Tests whether a class is a well known deserialization gadget entry point, namely aClassLoadersubclass or a JDK SQLDataSource/RowSetimplementation.static booleanisClob(Class clazz)static booleanisGenericParamType(Type type)static booleanisHibernateInitialized(Object object)static booleanisJacksonCreator(Method method)static booleanisKotlin(Class clazz)static booleanisNumber(String str)static booleanisPath(Class<?> clazz)static booleanisProxy(Class<?> clazz)static booleanisTransient(Method method)static booleanisXmlField(Class clazz)static Class<?>loadClass(String className)static Class<?>loadClass(String className, ClassLoader classLoader)static Class<?>loadClass(String className, ClassLoader classLoader, boolean cache)static longlongExtractValue(Number number)static longlongValue(BigDecimal decimal)static StringnormalizeAcceptName(String typeName)Normalizes a type name the way the autoType accept-list rolling hash normalizes it, so that a nested class matches whether it is written with its binary name (a.b.Outer$Inner) or its canonical name (a.b.Outer.Inner).static ObjectoptionalEmpty(Type type)static doubleparseDouble(String str)static floatparseFloat(String str)static shortshortValue(BigDecimal decimal)static LocaletoLocale(String strVal)static TypeunwrapOptional(Type type)
-
-
-
Field Detail
-
compatibleWithJavaBean
public static boolean compatibleWithJavaBean
-
compatibleWithFieldName
public static boolean compatibleWithFieldName
根据field name的大小写输出输入数据
-
fnv1a_64_magic_hashcode
public static final long fnv1a_64_magic_hashcode
- See Also:
- Constant Field Values
-
fnv1a_64_magic_prime
public static final long fnv1a_64_magic_prime
- See Also:
- Constant Field Values
-
-
Method Detail
-
isXmlField
public static boolean isXmlField(Class clazz)
-
getXmlAccessorType
public static Annotation getXmlAccessorType(Class clazz)
-
isClob
public static boolean isClob(Class clazz)
-
castToBigDecimal
public static BigDecimal castToBigDecimal(Object value)
-
castToBigInteger
public static BigInteger castToBigInteger(Object value)
-
longExtractValue
public static long longExtractValue(Number number)
-
isNumber
public static boolean isNumber(String str)
-
byteValue
public static byte byteValue(BigDecimal decimal)
-
shortValue
public static short shortValue(BigDecimal decimal)
-
intValue
public static int intValue(BigDecimal decimal)
-
longValue
public static long longValue(BigDecimal decimal)
-
castToBytes
public static byte[] castToBytes(Object value)
-
cast
public static <T> T cast(Object obj, Class<T> clazz, ParserConfig config)
-
castToEnum
public static <T> T castToEnum(Object obj, Class<T> clazz, ParserConfig mapping)
-
cast
public static <T> T cast(Object obj, Type type, ParserConfig mapping)
-
cast
public static <T> T cast(Object obj, ParameterizedType type, ParserConfig mapping)
-
castToJavaBean
public static <T> T castToJavaBean(Map<String,Object> map, Class<T> clazz, ParserConfig config)
-
clearClassMapping
public static void clearClassMapping()
-
isPath
public static boolean isPath(Class<?> clazz)
-
loadClass
public static Class<?> loadClass(String className, ClassLoader classLoader)
-
hasIllegalTypeNameChars
public static boolean hasIllegalTypeNameChars(String typeName)
Tests whether a type name carries a character that cannot appear in a Java binary class name but is meaningful in a URL. A nested jar URL such asjar:http://host/x.jar!/is resolvable by some class loaders, so a type name carrying one must never reach one.- Parameters:
typeName- the type name to test- Returns:
- true if the type name must be rejected without being resolved
-
normalizeAcceptName
public static String normalizeAcceptName(String typeName)
Normalizes a type name the way the autoType accept-list rolling hash normalizes it, so that a nested class matches whether it is written with its binary name (a.b.Outer$Inner) or its canonical name (a.b.Outer.Inner).- Parameters:
typeName- the type name to normalize- Returns:
- the normalized type name
-
isAutoTypeDenyClass
public static boolean isAutoTypeDenyClass(Class<?> type)
Tests whether a class is a well known deserialization gadget entry point, namely aClassLoadersubclass or a JDK SQLDataSource/RowSetimplementation. Such types must not be resolved by matching an autoType whitelist prefix; only an accept entry naming the type in full is treated as an explicit opt-in.- Parameters:
type- the class to test- Returns:
- true if the class must not be resolved through a whitelist prefix match
-
loadClass
public static Class<?> loadClass(String className, ClassLoader classLoader, boolean cache)
-
buildBeanInfo
public static SerializeBeanInfo buildBeanInfo(Class<?> beanType, Map<String,String> aliasMap, PropertyNamingStrategy propertyNamingStrategy)
-
buildBeanInfo
public static SerializeBeanInfo buildBeanInfo(Class<?> beanType, Map<String,String> aliasMap, PropertyNamingStrategy propertyNamingStrategy, boolean fieldBased)
-
computeGettersWithFieldBase
public static List<FieldInfo> computeGettersWithFieldBase(Class<?> clazz, Map<String,String> aliasMap, boolean sorted, PropertyNamingStrategy propertyNamingStrategy)
-
computeGetters
public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String,String> aliasMap)
-
computeGetters
public static List<FieldInfo> computeGetters(Class<?> clazz, Map<String,String> aliasMap, boolean sorted)
-
computeGetters
public static List<FieldInfo> computeGetters(Class<?> clazz, JSONType jsonType, Map<String,String> aliasMap, Map<String,Field> fieldCacheMap, boolean sorted, PropertyNamingStrategy propertyNamingStrategy)
-
getSuperMethodAnnotation
public static JSONField getSuperMethodAnnotation(Class<?> clazz, Method method)
-
isGenericParamType
public static boolean isGenericParamType(Type type)
-
getSerializeFeatures
public static int getSerializeFeatures(Class<?> clazz)
Deprecated.
-
getParserFeatures
public static int getParserFeatures(Class<?> clazz)
-
getPropertyNameByMethodName
public static String getPropertyNameByMethodName(String methodName)
resolve property name from get/set method name- Parameters:
methodName- get/set method name- Returns:
- property name
-
checkPrimitiveArray
public static Type checkPrimitiveArray(GenericArrayType genericArrayType)
-
createCollection
public static Collection createCollection(Type type)
-
isProxy
public static boolean isProxy(Class<?> clazz)
-
isTransient
public static boolean isTransient(Method method)
-
isAnnotationPresentOneToMany
public static boolean isAnnotationPresentOneToMany(Method method)
-
isAnnotationPresentManyToMany
public static boolean isAnnotationPresentManyToMany(Method method)
-
isHibernateInitialized
public static boolean isHibernateInitialized(Object object)
-
parseDouble
public static double parseDouble(String str)
-
parseFloat
public static float parseFloat(String str)
-
fnv1a_64_extract
public static long fnv1a_64_extract(String key)
-
fnv1a_64_lower
public static long fnv1a_64_lower(String key)
-
fnv1a_64
public static long fnv1a_64(String key)
-
isKotlin
public static boolean isKotlin(Class clazz)
-
getKotlinConstructor
public static Constructor getKotlinConstructor(Constructor[] constructors)
-
getKotlinConstructor
public static Constructor getKotlinConstructor(Constructor[] constructors, String[] paramNames)
-
getAnnotation
public static <A extends Annotation> A getAnnotation(Class<?> targetClass, Class<A> annotationClass)
-
getAnnotation
public static <A extends Annotation> A getAnnotation(Field field, Class<A> annotationClass)
-
getAnnotation
public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass)
-
getParameterAnnotations
public static Annotation[][] getParameterAnnotations(Method method)
-
getParameterAnnotations
public static Annotation[][] getParameterAnnotations(Constructor constructor)
-
isJacksonCreator
public static boolean isJacksonCreator(Method method)
-
-