我正在开发一个 Android 应用程序,与 GAE 服务器 + Objectify DB 通信。
我选择 Restlet 作为 rest 框架。
当我尝试检索具有 Key 属性的实体时遇到问题。服务器抛出错误:
org.codehaus.jackson.map.JsonMappingException: Direct self-reference leading to cycle
(through reference chain: java.util.ArrayList[0]->com.my.model.MyMessage["senderKey"]->com.googlecode.objectify.Key["root"])
这是我的模型(非常简单):
public class MyMessage implements Serializable {
private static final long serialVersionUID = -1075184303389185795L;
@Id
private Long id;
@Unindexed
private String sendMessage;
@Parent
Key<MyUser> senderKey;
private MyMessage() {
}
public MyMessage(MyUser user, String message) {
super();
this.sendMessage = message;
this.senderKey = new Key<MyUser>(MyUser.class, user.getId());
}
[... getters and setters ...]
}
.
public class MyUser implements Serializable {
private static final long serialVersionUID = 7390103290165670089L;
@Id private String id;
private MyUser() {
this.setId("default");
}
public MyUser(String mail) {
this.setId(mail);
}
[... getters and setters ...]
}
我能做些什么来解决这个问题??