Tyv*_*ain 3 java google-app-engine json restlet objectify
这个问题可能看起来很愚蠢,但对我来说,循环引用是例如对象 A 引用对象 B 而对象 B 引用对象 A。
我正在使用一个 android 应用程序与一个带有 objectify DB 的 GAE 服务器进行通信。
我的模型很简单,但出现错误:
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"])
Run Code Online (Sandbox Code Playgroud)
这是我的模型:MyMessage 指的是 MyUser(MyUser DOESNT 指的是 MyMessage...
这是代码:
public class MyMessage implements Serializable {
private static final long serialVersionUID = -1075184303389185795L;
@Id
private Long id;
@Unindexed
private String sendMessage;
@Unindexed
private String answerMessage;
private MessageStatus status = MessageStatus.FREE;
@Parent
Key<MyUser> senderKey;
Key<MyUser> answererKey;
@SuppressWarnings("unused")
private MyMessage() {
}
public MyMessage(MyUser user, String message) {
super();
this.sendMessage = message;
this.senderKey = new Key<MyUser>(MyUser.class, user.getId());
}
[... getters and setters ...]
}
Run Code Online (Sandbox Code Playgroud)
.
public class MyUser implements Serializable {
private static final long serialVersionUID = 7390103290165670089L;
@Id private String id;
@SuppressWarnings("unused")
private MyUser() {
this.setId("default");
}
public MyUser(String mail) {
this.setId(mail);
}
public void setId(String mail) {
this.id = mail;
}
public String getId() {
return id;
}
Run Code Online (Sandbox Code Playgroud)
}
那么究竟什么是直接自引用?我的模型有什么问题??
谢谢你。
| 归档时间: |
|
| 查看次数: |
9081 次 |
| 最近记录: |