【发布时间】:2019-05-06 22:14:36
【问题描述】:
将 Jackson 与 Retrofit 结合使用,我想在反序列化期间将朋友列表设置为 friendToMany。正如我已经完成的文档一样,我们必须在设置 assignable=true 时手动将该实体分配给 boxstore。所以,我正在这样做(如代码所示)。此方法仅适用于此代码所属的第一项。它不适用于元素 2 或更多元素。
@Id(assignable = true)
@JsonProperty("_id")
public long id;
@Transient
private List<Friend> friends = null;
@JsonIgnore
@Backlink(to = "demoResponseToOne")
ToMany<Friend> friendToMany;
@JsonProperty("friends")
public void setFriends(
List<Friend> friends)
{
this.friends = friends;
for (Friend friend : friends)
{
MyApplication.getBoxStore().boxFor(Friend.class).attach(friend);
friendToMany.add(friend);
}
}
抛出的异常是:io.objectbox.exception.DbDetachedException: Cannot resolve relation for detached entities, call box.attach(entity) beforehand.add(friend)。我的意思是当这个 Root 元素是列表的第一项时,这有效。
【问题讨论】:
标签: java android database jackson2 objectbox