You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
{"bridge":{"from":"zhangsan","to":"lisi"}}
com.alibaba.fastjson2.JSONException: invoke constructor error, public com.yiduo.jdk.example.Fastjson2ExampleTestCase$Transform(com.yiduo.jdk.example.Fastjson2ExampleTestCase$Bridge)
at com.alibaba.fastjson2.reader.ConstructorFunction.apply(ConstructorFunction.java:132)
at com.alibaba.fastjson2.reader.ConstructorFunction.apply(ConstructorFunction.java:15)
at com.alibaba.fastjson2.reader.ObjectReaderNoneDefaultConstructor.readObject(ObjectReaderNoneDefaultConstructor.java:351)
at com.alibaba.fastjson2.JSON.parseObject(JSON.java:864)
at com.yiduo.jdk.example.Fastjson2ExampleTestCase.testJDKRecord(Fastjson2ExampleTestCase.java:12)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:65)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
at com.alibaba.fastjson2.reader.ConstructorFunction.apply(ConstructorFunction.java:129)
... 7 more
Caused by: java.lang.ClassCastException: Cannot cast java.lang.String to com.yiduo.jdk.example.Fastjson2ExampleTestCase$Bridge
at java.base/java.lang.Class.cast(Class.java:4067)
at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62)
... 10 more
【测试代码二】
static class Transform2 {
private Bridge2 bridge;
public Transform2() {
}
public Transform2(String from, String to) {
this(new Bridge2(from, to));
}
public Transform2(Bridge2 bridge) {
this.bridge = bridge;
}
public Bridge2 getBridge() {
return bridge;
}
@Override
public String toString() {
return "Transform2{" +
"bridge=" + bridge +
'}';
}
}
static class Bridge2 {
private String from;
private String to;
public Bridge2() {
}
public Bridge2(String from, String to) {
this.from = from;
this.to = to;
}
public String getFrom() {
return from;
}
public String getTo() {
return to;
}
public void setFrom(String from) {
this.from = from;
}
public void setTo(String to) {
this.to = to;
}
@Override
public String toString() {
return "Bridge2{" +
"from='" + from + '\'' +
", to='" + to + '\'' +
'}';
}
}
【环境版本】
【测试代码一】
【期望输出】
【实际输出】
【测试代码二】
【期望输出】
【实际输出】
The text was updated successfully, but these errors were encountered: