Today, using fastJson to parse the error of create instance error
Carefully check that the fields in the bean class are the same as those returned by the server, and the format is correct, so why does an error be reported?
Find the answer online, if there is an embedded situation:
For example, public class A{
private String haha;
private int gogo;
private B bb;
The set and get methods are omitted. . . . .
public class B{
private String name;
private int price;
The set and get methods are omitted. . . . .}
}
B is nested in A, then we need to declare the embedded class static attribute, as follows (this problem is solved)
public class A{
private String haha;
private int gogo;
private B bb;
The set and get methods are omitted. . . . .
publicstatic class B{
private String name;
private int price;
The set and get methods are omitted. . . . .}
}
Original link: /gogolaile/article/details/54631139
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
According to the sharing of others in the group, this problem is mainly caused by the implementation mechanism of Java internal classes and nested classes. First of all, according to the Java programming idea, static internal classes are called nested classes. So what is the difference between the two? Although general internal classes are not written in the source code, after compilation, you will see that there is an additional reference to the external class. If you use the internal class for json serialization, an exception will be reported because its external class cannot be found. The nested classes are static and do not have default external class references, and they can be used even if there is no object of the external class. Therefore, there will be no errors when converting json.