我有以下课程:
public class MeetingCenter {
private String name;
private List<MeetingRoom> meetingRoomList;
}
public class MeetingRoom {
private MeetingCenter meetingCenter;
private String code;
private String name;
private List<Reservation> reservationList;
}
public class Reservation {
private MeetingRoom meetingRoom;
private String owner;
}
我想创建一个具有以下模式的 JSON:
这个方法在我调用 toJson() 方法的那一行抛出了一个异常:
private static void exportToJson(List<MeetingCenter> mcs) throws IOException {
Gson gson = new Gson();
String data = gson.toJson(mcs);
JsonWriter writer = new JsonWriter(new FileWriter("export.json"));
writer.setIndent(" "); // set indent
writer.beginObject(); // document start
writer.name("schema").value("PLUS4U.EBC.MCS.MeetingRoom_Schedule_1.0");
writer.name("uri").value("ues:UCL-BT:UCL.INF/DEMO_REZERVACE:EBC.MCS.DEMO/MR001/SCHEDULE");
writer.name("data").value(data);
writer.endObject(); // document end
writer.close();
}
例外:
Exception in thread "main" java.lang.StackOverflowError
at java.lang.StringBuffer.append(StringBuffer.java:380)
at java.io.StringWriter.write(StringWriter.java:77)
at com.google.gson.stream.JsonWriter.beforeName(JsonWriter.java:614)
at com.google.gson.stream.JsonWriter.writeDeferredName(JsonWriter.java:401)
at com.google.gson.stream.JsonWriter.beginArray(JsonWriter.java:287)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.write(CollectionTypeAdapterFactory.java:95)
....
肥皂起泡泡
PIPIONE
相关分类