Resolves an issue where the collection class member variables of an object become other types of objects during the conversion process.
public class A {
Private list<b> blist;
Public A (list<b> temp) {
blist = temp;
}
public void Setblist (list<b> temp) {
blist = temp;
}
Public list<b> getblist () {
return blist;
}
}
public class mainclass{
public static void Main (String args[]) {
List <A> al = new Arraylist<a> ();
List <B> bl = new arraylist<b> ();
Bl.add (New B ());
Al.add (new A (BL));
Prevent the cycle of death
Jsonconfig jsonconfig = new Jsonconfig ();
Jsonconfig.setcycledetectionstrategy (cycledetectionstrategy.lenient);
Into the jsonarray of the ToString to the front desk.
String result = Jsonarray.fromobject (AL, Jsonconfig). toString ();
Front desk stringify array, upload to backstage and change back
Jsonconfig jsonconfig = new Jsonconfig ();
Jsonconfig.setcycledetectionstrategy (cycledetectionstrategy.lenient);
Jsonarray Jsonarray = jsonarray.fromobject (result);
list<a> al1= new arraylist<a> ();
It is not possible to use jsonarray.tocollection () directly in the collection class, and then set it to the parent class, otherwise it becomes a different object.
for (int i = 0; i < jsonarray.size (); i++) {
Jsonobject json = Jsonarray.getjsonobject (i);
Jsonarray blist = Json.getjsonarray ("blist");
@SuppressWarnings ("Unchecked")
List<b> blist= (list<b>) jsonarray.tocollection (blist, B.class);
A ob1 = (groupproperty) Jsonobject.tobean (JSON, a.class);
Ob1.setblist (blist);
Al1.add (OB1);
}
Al1 's right here.
System.out.println (AL1);
}
}
Resolves the jsonobject/jsonarray of nested list types into the original list problem.