mirror of
https://github.com/alibaba/fastjson.git
synced 2026-10-28 13:50:47 +08:00
mixin support jsoncreator
This commit is contained in:
@@ -7,6 +7,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.PropertyNamingStrategy;
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
@@ -315,7 +316,23 @@ public class JavaBeanInfo {
|
||||
|
||||
boolean isInterfaceOrAbstract = clazz.isInterface() || Modifier.isAbstract(clazz.getModifiers());
|
||||
if ((defaultConstructor == null && builderClass == null) || isInterfaceOrAbstract) {
|
||||
creatorConstructor = getCreatorConstructor(constructors);
|
||||
|
||||
Type mixInType = JSON.getMixInAnnotations(clazz);
|
||||
if (mixInType instanceof Class) {
|
||||
Constructor<?>[] mixInConstructors = ((Class<?>) mixInType).getConstructors();
|
||||
Constructor<?> mixInCreator = getCreatorConstructor(mixInConstructors);
|
||||
if (mixInCreator != null) {
|
||||
try {
|
||||
creatorConstructor = clazz.getConstructor(mixInCreator.getParameterTypes());
|
||||
} catch (NoSuchMethodException e) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (creatorConstructor == null) {
|
||||
creatorConstructor = getCreatorConstructor(constructors);
|
||||
}
|
||||
|
||||
if (creatorConstructor != null && !isInterfaceOrAbstract) { // 基于标记 JSONCreator 注解的构造方法
|
||||
TypeUtils.setAccessible(creatorConstructor);
|
||||
|
||||
@@ -3,12 +3,9 @@ package com.alibaba.json.bvt.issue_3400;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.annotation.JSONCreator;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Issue3436 extends TestCase {
|
||||
public void test_for_issue() throws Exception {
|
||||
JSON.addMixInAnnotations(FileSystemResource.class, FileSystemResourceMixedIn.class);
|
||||
|
||||
Reference in New Issue
Block a user