FasterXML / jackson-modules-java8

Set of support modules for Java 8 datatypes (Optionals, date/time) and features (parameter names)
Apache License 2.0
401 stars 117 forks source link

Can not serialize java 8 stream with StackOverflowError #174

Closed ilumer closed 4 years ago

ilumer commented 4 years ago

I try to use stream api to get all elements recursive, but this method throw a infinite recursion (StackOverflowError)。I can not find problem in my code,I try to build a small code to reproduce this scenario,I find the reason that produce error is I register the Jdk8Module. If i remove this module , it work right. Can you give me some suggestions, thank you.

cowtowncoder commented 4 years ago

But isn't your content here cyclic, with a.elStream pointing back to a? That would lead to infinite recursion. I am not sure how else it should work; either it is necessary to prevent cyclic references with @JsonIgnore on right fields, or to use Object Id handling (@JsonIdentityInfo).

As to including jackson-datatype-jdk8: without it Stream is only seen as POJO, probably with parallel (from boolean isParallel()).

ilumer commented 4 years ago

Thanks for replaying,I just think Stream is only seen as POJO, so it should not throw StackOverflowError. I can not find that it handle the stream specially, I should read the doc more carefully.