in core/src/main/java/com/alibaba/fastjson2/writer/ObjectWriterBaseModule.java [56:273]
public void getBeanInfo(BeanInfo beanInfo, Class objectClass) {
if (objectClass != null) {
Class superclass = objectClass.getSuperclass();
if (superclass != Object.class && superclass != null && superclass != Enum.class) {
getBeanInfo(beanInfo, superclass);
}
Class[] interfaces = objectClass.getInterfaces();
for (Class item : interfaces) {
if (item == Serializable.class) {
continue;
}
getBeanInfo(beanInfo, item);
}
if (beanInfo.seeAlso != null && beanInfo.seeAlsoNames != null) {
for (int i = 0; i < beanInfo.seeAlso.length; i++) {
Class seeAlso = beanInfo.seeAlso[i];
if (seeAlso == objectClass && i < beanInfo.seeAlsoNames.length) {
String seeAlsoName = beanInfo.seeAlsoNames[i];
if (seeAlsoName != null && seeAlsoName.length() != 0) {
beanInfo.typeName = seeAlsoName;
break;
}
}
}
}
}
Annotation jsonType1x = null;
JSONType jsonType = null;
Annotation[] annotations = getAnnotations(objectClass);
for (int i = 0; i < annotations.length; i++) {
Annotation annotation = annotations[i];
Class annotationType = annotation.annotationType();
if (jsonType == null) {
jsonType = findAnnotation(annotation, JSONType.class);
}
if (jsonType == annotation) {
continue;
}
if (annotationType == JSONCompiler.class) {
JSONCompiler compiler = (JSONCompiler) annotation;
if (compiler.value() == JSONCompiler.CompilerOption.LAMBDA) {
beanInfo.writerFeatures |= FieldInfo.JIT;
}
}
boolean useJacksonAnnotation = JSONFactory.isUseJacksonAnnotation();
switch (annotationType.getName()) {
case "com.alibaba.fastjson.annotation.JSONType":
jsonType1x = annotation;
break;
case "com.fasterxml.jackson.annotation.JsonIgnoreProperties":
if (useJacksonAnnotation) {
processJacksonJsonIgnoreProperties(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.annotation.JsonPropertyOrder":
if (useJacksonAnnotation) {
processJacksonJsonPropertyOrder(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.annotation.JsonFormat":
if (useJacksonAnnotation) {
processJacksonJsonFormat(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.annotation.JsonInclude":
if (useJacksonAnnotation) {
processJacksonJsonInclude(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.annotation.JsonTypeInfo":
if (useJacksonAnnotation) {
processJacksonJsonTypeInfo(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.databind.annotation.JsonSerialize":
if (useJacksonAnnotation) {
processJacksonJsonSerialize(beanInfo, annotation);
if (beanInfo.serializer != null && Enum.class.isAssignableFrom(objectClass)) {
beanInfo.writeEnumAsJavaBean = true;
}
}
break;
case "com.fasterxml.jackson.annotation.JsonTypeName":
if (useJacksonAnnotation) {
processJacksonJsonTypeName(beanInfo, annotation);
}
break;
case "com.fasterxml.jackson.annotation.JsonSubTypes":
if (useJacksonAnnotation) {
processJacksonJsonSubTypes(beanInfo, annotation);
}
break;
case "kotlin.Metadata":
beanInfo.kotlin = true;
KotlinUtils.getConstructor(objectClass, beanInfo);
break;
default:
break;
}
}
if (jsonType == null) {
Class mixInSource = provider.mixInCache.get(objectClass);
if (mixInSource != null) {
beanInfo.mixIn = true;
Annotation[] mixInAnnotations = getAnnotations(mixInSource);
for (int i = 0; i < mixInAnnotations.length; i++) {
Annotation annotation = mixInAnnotations[i];
Class<? extends Annotation> annotationType = annotation.annotationType();
jsonType = findAnnotation(annotation, JSONType.class);
if (jsonType == annotation) {
continue;
}
String annotationTypeName = annotationType.getName();
if ("com.alibaba.fastjson.annotation.JSONType".equals(annotationTypeName)) {
jsonType1x = annotation;
}
}
}
}
if (jsonType != null) {
Class<?>[] classes = jsonType.seeAlso();
if (classes.length != 0) {
beanInfo.seeAlso = classes;
}
String typeKey = jsonType.typeKey();
if (!typeKey.isEmpty()) {
beanInfo.typeKey = typeKey;
}
String typeName = jsonType.typeName();
if (!typeName.isEmpty()) {
beanInfo.typeName = typeName;
}
for (JSONWriter.Feature feature : jsonType.serializeFeatures()) {
beanInfo.writerFeatures |= feature.mask;
}
beanInfo.namingStrategy =
jsonType.naming().name();
String[] ignores = jsonType.ignores();
if (ignores.length > 0) {
beanInfo.ignores = ignores;
}
String[] includes = jsonType.includes();
if (includes.length > 0) {
beanInfo.includes = includes;
}
String[] orders = jsonType.orders();
if (orders.length > 0) {
beanInfo.orders = orders;
}
Class<?> serializer = jsonType.serializer();
if (ObjectWriter.class.isAssignableFrom(serializer)) {
beanInfo.serializer = serializer;
beanInfo.writeEnumAsJavaBean = true;
}
Class<? extends Filter>[] serializeFilters = jsonType.serializeFilters();
if (serializeFilters.length != 0) {
beanInfo.serializeFilters = serializeFilters;
}
String format = jsonType.format();
if (!format.isEmpty()) {
beanInfo.format = format;
}
String locale = jsonType.locale();
if (!locale.isEmpty()) {
String[] parts = locale.split("_");
if (parts.length == 2) {
beanInfo.locale = new Locale(parts[0], parts[1]);
}
}
if (!jsonType.alphabetic()) {
beanInfo.alphabetic = false;
}
if (jsonType.writeEnumAsJavaBean()) {
beanInfo.writeEnumAsJavaBean = true;
}
String rootName = jsonType.rootName();
if (!rootName.isEmpty()) {
beanInfo.rootName = rootName;
}
} else if (jsonType1x != null) {
final Annotation annotation = jsonType1x;
BeanUtils.annotationMethods(jsonType1x.annotationType(), method -> BeanUtils.processJSONType1x(beanInfo, annotation, method));
}
if (beanInfo.seeAlso != null && beanInfo.seeAlso.length != 0
&& (beanInfo.typeName == null || beanInfo.typeName.length() == 0)) {
for (Class seeAlsoClass : beanInfo.seeAlso) {
if (seeAlsoClass == objectClass) {
beanInfo.typeName = objectClass.getSimpleName();
break;
}
}
}
}