Getting stack overflows upon json serialization after migrating to 2.8


Today I tried migrating from 2.7.3 to 2.8 and now running into test failures with play.libs.Json.toJson. Not really sure if it has to with Ebean or Json cause I’m serializing Ebean enhanced models in these error cases, for example:

java.lang.IllegalArgumentException: Infinite recursion (StackOverflowError) (through reference chain: java.util.HashMap["4"]->backend.models.GradeScale["grades"]->io.ebean.common.BeanSet[0]->backend.models.Grade["_ebean_intercept"]->io.ebean.bean.EntityBeanIntercept["persistenceContext"]->io.ebeaninternal.server.transaction.DefaultPersistenceContext["typeCache"]->java.util.HashMap["class backend.models.GradeScale"]...
at play.libs.Json.toJson(

Here I’m serializing a set of courses and the reference chain is like

class Course extends Model {
    private GradeScale gradeScale;
class GradeScale extends Model {
    @OneToMany(mappedBy = "gradeScale", cascade = CascadeType.ALL)
    private Set<Grade> grades;
class Grade extends Model {
    private GradeScale gradeScale;

So it seems that underlying Jackson serializer gets confused with Ebean’s persistence layer or something like that. If I switch to using Ebean.Json.toJson then serialization works but then again it does a bit different thing and I’d like to stick with play-json in this case. Any clues? Does Ebean actually support 2.8 yet? I read that Jackson got an upgrade in 2.8 so maybe it’s got to do with that.

Play 2.8
Play-json 2.8
Play-Ebean 5.0.2

Oh, I guess it’s already reported here :)

Hi @lluque,

There is an issue discussing this here: