JsonMappingException: infinite recursion on OneToMany relationships in Objectify

To serve the backend for an Android application, I use it Google App Enginewith Objectify(4.0.3b).

On the backend, I have a simple UserEntity that has list of Users(friends) as a relationship.

@Entity
public class User {

    @Id
    private String email;
    @Load
    private List<Ref<User>> friends = new ArrayList<Ref<User>>();

    private User() {
    }

    public List<User> getFriends() {
        ArrayList<User> friendList = new ArrayList<User>();
        for (Ref<User> ref : this.friends) {
            friendList.add(ref.get());
        }
        return friendList;
    }

    public void setFriends(List<User> friends) {
        List<Ref<User>> refs = new ArrayList<Ref<User>>();
        for (User user : friends) {
            refs.add(Ref.create(user));
        }
        this.friends = refs;
    }

}

Now that I have the following Users stored in the database, for example: user1and user2:

user1has user2friends in his list and vice versa

When trying to get a User object (which has a link ) from my endpoint, the Android client throws the following exception:

com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: java.util.ArrayList[0]...

Jackson JSON Hibernate JPA @JsonIgnore getter/setter. getter/setter ( ), .

- @JsonManagedReference @JsonBackReference, ManagedReference BackReference friends.

, , , , - @JsonIdentityInfo , Jackson 2.0.

, , Google App Engine. GAE jackson-core-asl-1.9.11, , , @JsonIdentityInfo, , , 2.0.

- , Jackson (2.4) Google App Engine @JsonIdentityInfo?

?

+4
1

DTO JSON ( , ).

0

All Articles