creatorConstructor.setAccessible(true);
beanInfo.setCreatorConstructor(creatorConstructor);
for (int i = 0; i < creatorConstructor.getParameterTypes().length; ++i) {
Annotation[] paramAnnotations = creatorConstructor.getParameterAnnotations()[i];
JSONField fieldAnnotation = null;
for (Annotation paramAnnotation : paramAnnotations) {
if (paramAnnotation instanceof JSONField) {
fieldAnnotation = (JSONField) paramAnnotation;
break;
}
}
if (fieldAnnotation == null) {
throw new JSONException("illegal json creator");
}
Class<?> fieldClass = creatorConstructor.getParameterTypes()[i];
Type fieldType = creatorConstructor.getGenericParameterTypes()[i];
Field field = getField(clazz, fieldAnnotation.name());
FieldInfo fieldInfo = new FieldInfo(fieldAnnotation.name(), clazz, fieldClass, fieldType, field);
beanInfo.add(fieldInfo);
}
return beanInfo;
}
Method factoryMethod = getFactoryMethod(clazz);
if (factoryMethod != null) {
factoryMethod.setAccessible(true);
beanInfo.setFactoryMethod(factoryMethod);
for (int i = 0; i < factoryMethod.getParameterTypes().length; ++i) {
Annotation[] paramAnnotations = factoryMethod.getParameterAnnotations()[i];
JSONField fieldAnnotation = null;
for (Annotation paramAnnotation : paramAnnotations) {
if (paramAnnotation instanceof JSONField) {
fieldAnnotation = (JSONField) paramAnnotation;
break;
}
}
if (fieldAnnotation == null) {
throw new JSONException("illegal json creator");
}
Class<?> fieldClass = factoryMethod.getParameterTypes()[i];
Type fieldType = factoryMethod.getGenericParameterTypes()[i];
Field field = getField(clazz, fieldAnnotation.name());
FieldInfo fieldInfo = new FieldInfo(fieldAnnotation.name(), clazz, fieldClass, fieldType, field);
beanInfo.add(fieldInfo);
}
return beanInfo;
}
throw new JSONException("default constructor not found. " + clazz);
}
for (Method method : clazz.getMethods()) {
String methodName = method.getName();
if (methodName.length() < 4) {
continue;
}
if (Modifier.isStatic(method.getModifiers())) {
continue;
}
// support builder set
if (!(method.getReturnType().equals(Void.TYPE) || method.getReturnType().equals(clazz))) {
continue;
}
if (method.getParameterTypes().length != 1) {
continue;
}
JSONField annotation = method.getAnnotation(JSONField.class);
if (annotation == null) {
annotation = TypeUtils.getSupperMethodAnnotation(clazz, method);
}
if (annotation != null) {
if (!annotation.deserialize()) {
continue;
}
if (annotation.name().length() != 0) {
String propertyName = annotation.name();
beanInfo.add(new FieldInfo(propertyName, method, null, clazz, type));
method.setAccessible(true);
continue;
}
}
if (!methodName.startsWith("set")) {
continue;
}
char c3 = methodName.charAt(3);
String propertyName;
if (Character.isUpperCase(c3)) {
if (methodName.length() > 4 && Character.isUpperCase(methodName.charAt(4))) {
propertyName = methodName.substring(3);
} else {
propertyName = Character.toLowerCase(methodName.charAt(3)) + methodName.substring(4);
}
} else if (c3 == '_') {
propertyName = methodName.substring(4);
} else if (c3 == 'f') {
propertyName = methodName.substring(3);
} else {
continue;
}
Field field = getField(clazz, propertyName);
if (field != null) {
JSONField fieldAnnotation = field.getAnnotation(JSONField.class);
if (fieldAnnotation != null && fieldAnnotation.name().length() != 0) {
propertyName = fieldAnnotation.name();
beanInfo.add(new FieldInfo(propertyName, method, field, clazz, type));
continue;
}
}
beanInfo.add(new FieldInfo(propertyName, method, null, clazz, type));
method.setAccessible(true);
}
for (Field field : clazz.getFields()) {
if (Modifier.isStatic(field.getModifiers())) {
continue;
}
boolean contains = false;
for (FieldInfo item : beanInfo.getFieldList()) {
if (item.getName().equals(field.getName())) {
contains = true;
continue;
}
}
if (contains) {
continue;
}
String propertyName = field.getName();
JSONField fieldAnnotation = field.getAnnotation(JSONField.class);
if (fieldAnnotation != null && fieldAnnotation.name().length() != 0) {
propertyName = fieldAnnotation.name();
}
beanInfo.add(new FieldInfo(propertyName, null, field, clazz, type));
}
for (Method method : clazz.getMethods()) {