Package com.alibaba.fastjson2.util
Class BeanUtils
- java.lang.Object
-
- com.alibaba.fastjson2.util.BeanUtils
-
public abstract class BeanUtils extends Object
- Author:
- Bob Lee, Jesse Wilson, Shaojin Wen
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBeanUtils.GenericArrayTypeImpl
-
Constructor Summary
Constructors Constructor Description BeanUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidannotationMethods(Class objectClass, Consumer<Method> methodConsumer)static GenericArrayTypearrayOf(Type componentType)Returns an array type whose elements are all instances ofcomponentType.static MethodbuildMethod(Class objectClass, String methodName)static Typecanonicalize(Type type)Returns a type that is functionally equal but not necessarily equal according toObject.equals().static voidcleanupCache(Class objectClass)static voidcleanupCache(ClassLoader classLoader)static voidconstructor(Class objectClass, Consumer<Constructor> constructorConsumer)static voiddeclaredFields(Class objectClass, Consumer<Field> fieldConsumer)ignore static fieldsstatic booleanequals(Type a, Type b)Returns true ifaandbare equal.static StringfieldName(String methodName, String namingStrategy)static voidfields(Class objectClass, Consumer<Field> fieldReaders)static <A extends Annotation>
AfindAnnotation(Annotation annotation, Class<A> annotationType)If theannotation's annotationType is notannotationType, then to find the first annotation ofannotationTypethat is either directly present, meta-present, or indirectly present on the suppliedelement.static <A extends Annotation>
AfindAnnotation(AnnotatedElement element, Class<A> annotationType)Find the first annotation ofannotationTypethat is either directly present, meta-present, or indirectly present on the suppliedelement.static MethodfluentSetter(Class objectClass, String methodName, Class paramType)static Annotation[]getAnnotations(AnnotatedElement element)static Constructor[]getConstructor(Class objectClass)static FieldgetDeclaredField(Class objectClass, String fieldName)static ConstructorgetDefaultConstructor(Class objectClass, boolean includeNoneStaticMember)static String[]getEnumAnnotationNames(Class enumClass)static MembergetEnumValueField(Class enumClass, ObjectCodecProvider mixinProvider)static FieldgetField(Class objectClass, Method method)static TypegetFieldType(TypeReference typeReference, Class<?> raw, Member field, Type fieldType)static MethodgetMethod(Class objectClass, Method signature)static MethodgetMethod(Class objectClass, String methodName)static TypegetParamType(TypeReference type, Class<?> raw, Class declaringClass, Parameter field, Type fieldType)static Class<?>getRawType(Type type)static String[]getRecordFieldNames(Class<?> recordType)static MethodgetSetter(Class objectClass, String methodName)static StringgetterName(Method method, boolean kotlin, String namingStrategy)static StringgetterName(Method method, String namingStrategy)static StringgetterName(String methodName, String namingStrategy)static voidgetters(Class objectClass, Class mixinSource, boolean kotlin, Consumer<Method> methodConsumer)static voidgetters(Class objectClass, Class mixinSource, Consumer<Method> methodConsumer)static voidgetters(Class objectClass, Consumer<Method> methodConsumer)static booleanhasPublicDefaultConstructor(Class objectClass)static booleanisExtendedMap(Class objectClass)static booleanisNoneStaticMemberClass(Class objectClass, Class memberClass)static booleanisRecord(Class objectClass)static booleanisWriteEnumAsJavaBean(Class clazz)static ParameterizedTypenewParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.static voidprocessGsonSerializedName(FieldInfo fieldInfo, Annotation annotation)static voidprocessJacksonJsonFormat(BeanInfo beanInfo, Annotation annotation)static voidprocessJacksonJsonFormat(FieldInfo fieldInfo, Annotation annotation)static voidprocessJacksonJsonIgnore(FieldInfo fieldInfo, Annotation annotation)static voidprocessJacksonJsonInclude(BeanInfo beanInfo, Annotation annotation)static voidprocessJacksonJsonInclude(FieldInfo fieldInfo, Annotation annotation)static voidprocessJacksonJsonSubTypesType(BeanInfo beanInfo, int index, Annotation annotation)static voidprocessJacksonJsonTypeName(BeanInfo beanInfo, Annotation annotation)static voidprocessJacksonJsonUnwrapped(FieldInfo fieldInfo, Annotation annotation)static voidprocessJSONType1x(BeanInfo beanInfo, Annotation jsonType1x, Method method)static Typeresolve(Type context, Class<?> contextRawType, Type toResolve)static voidsetNoneStaticMemberClassParent(Object object, Object parent)static StringsetterName(String methodName, int prefixLength)static StringsetterName(String methodName, String namingStrategy)static voidsetters(Class objectClass, boolean checkPrefix, Consumer<Method> methodConsumer)static voidsetters(Class objectClass, BeanInfo beanInfo, Class mixin, Consumer<Method> methodConsumer)static voidsetters(Class objectClass, Class mixin, Consumer<Method> methodConsumer)static voidsetters(Class objectClass, Consumer<Method> methodConsumer)static voidstaticMethod(Class objectClass, Consumer<Method> methodConsumer)static WildcardTypesubtypeOf(Type bound)Returns a type that represents an unknown type that extendsbound.static WildcardTypesupertypeOf(Type bound)Returns a type that represents an unknown supertype ofbound.static StringtypeToString(Type type)
-
-
-
Field Detail
-
SUPER
public static final String SUPER
- See Also:
- Constant Field Values
-
-
Method Detail
-
fluentSetter
public static Method fluentSetter(Class objectClass, String methodName, Class paramType)
-
declaredFields
public static void declaredFields(Class objectClass, Consumer<Field> fieldConsumer)
ignore static fields
-
constructor
public static void constructor(Class objectClass, Consumer<Constructor> constructorConsumer)
-
getConstructor
public static Constructor[] getConstructor(Class objectClass)
-
hasPublicDefaultConstructor
public static boolean hasPublicDefaultConstructor(Class objectClass)
-
getDefaultConstructor
public static Constructor getDefaultConstructor(Class objectClass, boolean includeNoneStaticMember)
-
setters
public static void setters(Class objectClass, Class mixin, Consumer<Method> methodConsumer)
-
setters
public static void setters(Class objectClass, BeanInfo beanInfo, Class mixin, Consumer<Method> methodConsumer)
-
setters
public static void setters(Class objectClass, boolean checkPrefix, Consumer<Method> methodConsumer)
-
annotationMethods
public static void annotationMethods(Class objectClass, Consumer<Method> methodConsumer)
-
isWriteEnumAsJavaBean
public static boolean isWriteEnumAsJavaBean(Class clazz)
-
getEnumValueField
public static Member getEnumValueField(Class enumClass, ObjectCodecProvider mixinProvider)
-
getters
public static void getters(Class objectClass, Class mixinSource, Consumer<Method> methodConsumer)
-
getters
public static void getters(Class objectClass, Class mixinSource, boolean kotlin, Consumer<Method> methodConsumer)
-
isRecord
public static boolean isRecord(Class objectClass)
-
getFieldType
public static Type getFieldType(TypeReference typeReference, Class<?> raw, Member field, Type fieldType)
-
getParamType
public static Type getParamType(TypeReference type, Class<?> raw, Class declaringClass, Parameter field, Type fieldType)
-
newParameterizedTypeWithOwner
public static ParameterizedType newParameterizedTypeWithOwner(Type ownerType, Type rawType, Type... typeArguments)
Returns a new parameterized type, applyingtypeArgumentstorawTypeand enclosed byownerType.- Returns:
- a
serializableparameterized type.
-
arrayOf
public static GenericArrayType arrayOf(Type componentType)
Returns an array type whose elements are all instances ofcomponentType.- Returns:
- a
serializablegeneric array type.
-
subtypeOf
public static WildcardType subtypeOf(Type bound)
Returns a type that represents an unknown type that extendsbound. For example, ifboundisCharSequence.class, this returns? extends CharSequence. IfboundisObject.class, this returns?, which is shorthand for? extends Object.
-
supertypeOf
public static WildcardType supertypeOf(Type bound)
Returns a type that represents an unknown supertype ofbound. For example, ifboundisString.class, this returns? super String.
-
canonicalize
public static Type canonicalize(Type type)
Returns a type that is functionally equal but not necessarily equal according toObject.equals(). The returned type isSerializable.
-
findAnnotation
public static <A extends Annotation> A findAnnotation(AnnotatedElement element, Class<A> annotationType)
Find the first annotation ofannotationTypethat is either directly present, meta-present, or indirectly present on the suppliedelement.If the element is a class and the annotation is neither directly present nor meta-present on the class, this method will additionally search on interfaces implemented by the class before finding an annotation that is indirectly present on the class.
- Type Parameters:
A- the annotation- Parameters:
element- the element on which to search for the annotationannotationType- the annotation type of need to search- Returns:
- the searched annotation type
-
findAnnotation
public static <A extends Annotation> A findAnnotation(Annotation annotation, Class<A> annotationType)
If theannotation's annotationType is notannotationType, then to find the first annotation ofannotationTypethat is either directly present, meta-present, or indirectly present on the suppliedelement.- Type Parameters:
A- the searched annotation type- Parameters:
annotation- annotationannotationType- the annotation type of need to search- Returns:
- the searched annotation
-
getAnnotations
public static Annotation[] getAnnotations(AnnotatedElement element)
-
processJacksonJsonIgnore
public static void processJacksonJsonIgnore(FieldInfo fieldInfo, Annotation annotation)
-
isNoneStaticMemberClass
public static boolean isNoneStaticMemberClass(Class objectClass, Class memberClass)
-
setNoneStaticMemberClassParent
public static void setNoneStaticMemberClassParent(Object object, Object parent)
-
cleanupCache
public static void cleanupCache(Class objectClass)
-
cleanupCache
public static void cleanupCache(ClassLoader classLoader)
-
processJSONType1x
public static void processJSONType1x(BeanInfo beanInfo, Annotation jsonType1x, Method method)
-
processJacksonJsonFormat
public static void processJacksonJsonFormat(FieldInfo fieldInfo, Annotation annotation)
-
processJacksonJsonFormat
public static void processJacksonJsonFormat(BeanInfo beanInfo, Annotation annotation)
-
processJacksonJsonInclude
public static void processJacksonJsonInclude(BeanInfo beanInfo, Annotation annotation)
-
processJacksonJsonInclude
public static void processJacksonJsonInclude(FieldInfo fieldInfo, Annotation annotation)
-
processJacksonJsonUnwrapped
public static void processJacksonJsonUnwrapped(FieldInfo fieldInfo, Annotation annotation)
-
processJacksonJsonTypeName
public static void processJacksonJsonTypeName(BeanInfo beanInfo, Annotation annotation)
-
processJacksonJsonSubTypesType
public static void processJacksonJsonSubTypesType(BeanInfo beanInfo, int index, Annotation annotation)
-
processGsonSerializedName
public static void processGsonSerializedName(FieldInfo fieldInfo, Annotation annotation)
-
isExtendedMap
public static boolean isExtendedMap(Class objectClass)
-
-