On Fri, Sep 7, 2018 at 12:43 PM <[email protected]> wrote: > > I defined a class like this: > > public class Record1 extends AbstractList<Record1> { > int field1; > int field2; > > public int size() { > return 1; > } > public Record1 get(int index){ > if(index == 0){ > return this; > }else{ > throw exception; > } > } > } > > As above definition showing, the Record1 class is a list with only one item, > and the only item is it self. > > When I serialize a instance if Record1 class using jackson, it treat that > object as a list, and try to serialize the first item in list, but the first > item of list is also the list itself, and thus lead a StackOverflow: > > Caused by: java.lang.StackOverflowError > at > com.fasterxml.jackson.databind.SerializerProvider.getAttribute(SerializerProvider.java:398) > at > com.fasterxml.jackson.databind.ser.std.StdSerializer.findContextualConvertingSerializer(StdSerializer.java:364) > at > com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase.createContextual(AsArraySerializerBase.java:194) > at > com.fasterxml.jackson.databind.SerializerProvider.handleSecondaryContextualization(SerializerProvider.java:1004) > at > com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:524) > at > com.fasterxml.jackson.databind.ser.impl.PropertySerializerMap.findAndAddSecondarySerializer(PropertySerializerMap.java:90) > at > com.fasterxml.jackson.databind.ser.std.AsArraySerializerBase._findAndAddDynamic(AsArraySerializerBase.java:305) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:140) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:25) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serializeContents(CollectionSerializer.java:145) > at > com.fasterxml.jackson.databind.ser.std.CollectionSerializer.serialize(CollectionSerializer.java:107) > at com.fasterxml.jackson
Yes. What else do you expect to happen? You have self-reference which is problematic. What kind of output are you trying to produce? -+ Tatu +- -- You received this message because you are subscribed to the Google Groups "jackson-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/d/optout.
