私は次のモデルを持っています:
public class CategoryModel {
public String id;
public String name;
public String imageUrl;
public CategoryModel parent;
public List<CategoryModel> childrens = new ArrayList<CategoryModel>();
}
Spring MVc + jackson を使用して Json を返しています。
私のアクションは次のモデルを構築し、実行後にスタックオーバーフロー例外を取得します。
List<CategoryModel> allCategories = new ArrayList<CategoryModel>();
CategoryModel model = new CategoryModel();
model.id = "1";
model.name = "category 1";
CategoryModel model1 = new CategoryModel();
model.id = "2";
model.name = "category 1.1";
model.childrens.add(model1);
model1.parent = model;
allCategories.add(model);
私の問題は何ですか?
これはログファイルです (その一部):
org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) で org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) で org.codehaus.jackson .map.ser.BeanSerializer.serialize(BeanSerializer.java:112) org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122) org.codehaus.jackson.map.ser .std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71) org.codehaus.jackson.map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86) org.codehaus.jackson.map.ser.BeanPropertyWriter org.codehaus.jackson.map.ser.std.BeanSerializerBase の .serializeAsField(BeanPropertyWriter.java:446)。serializeFields(BeanSerializerBase.java:150) の org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) の org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) で org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) で org.codehaus.jackson .map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122) at org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71) at org.codehaus.jackson org.codehaus.jackson.map.ser の .map.ser.std.AsArraySerializerBase.serialize(AsArraySerializerBase.java:86)。org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) の BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer. java:112) org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:446) で org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) で org .codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) org.codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122) org.codehaus.jackson .map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71) org.codehaus.org.codehaus.jackson.map.ser. org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) の std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter. java:446) org.codehaus.jackson.map.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:150) で org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:112) で org .codehaus.jackson.map.ser.std.StdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:122) org.codehaus.jackson.map.ser.stdStdContainerSerializers$IndexedListSerializer.serializeContents(StdContainerSerializers.java:71) 原因: java.lang.StackOverflowError