Reputation: 327
First I tried this to send back a list response (I'm using AJAX so at the done part I'm expecting the list response):
@RequestMapping(value = "/a", method = RequestMethod.POST)
public @ResponseBody List<Xy> a( @RequestBody OtherClass oc, Model model) {
....codes
List<Xy> objList = xyRepository.findAll();
return objList;
}
Then this:
@RequestMapping(value = "/a", method = RequestMethod.POST)
public @ResponseBody ListWrapper a( @RequestBody OtherClass oc, Model model) {
...codes
List<Xy> objList = xyRepository.findAll();
ListWrapper lw = new ListWrapper();
lw.setObjList(objList);
return lw;
}
However with both of them I get the same error which is repeated many times but it is not looping forever so I can navigate in the site.
:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:149) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:111) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:24) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:157) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:693) ~[jackson-databind-2.6.5.jar:2.6.5]
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:675) ~[jackson-databind-2.6.5.jar:2.6.5]
Upvotes: 0
Views: 635
Reputation: 9516
Looks like you have a circular reference in the class returned from the repository (xy).
Set a breakpoint at BeanSerializer.157 or in any of the other locations from the stacktrace. Then you have the chance to see, which properties the serisalizer tries to serialize. From that you should be able to find the problematic property.
Once you found the problematic property you could exclude it from JSON serialization. You could do this with
@JsonIgnoreProperties({"foobar"})
Upvotes: 2