gpt4 book ai didi

android - Realm - 跳过以编程方式编写嵌套对象

转载 作者:搜寻专家 更新时间:2023-10-30 23:40:09 24 4
gpt4 key购买 nike

我已经看到对某些字段使用@Ignore,但我正在寻找稍微不同的东西。 https://realm.io/docs/java/latest/#models

是否可以指定在将父对象写入 Realm 时跳过嵌套对象?

这样做的原因:

我有一个复杂的 JSON 对象,我正在解析它然后保存到我的 Realm 。

这个对象可以变得非常大,所以我的后端有一些优化返回:

  • 一个完整的对象
  • 一个预览对象

在某些时候,我得到一个预览用户对象,它只返回字段的一个子集。

当保存到 Realm 时,这会覆盖整个对象(如预期的那样)并删除不存在的字段。

问题是我以后仍然需要那些删除的字段。

最佳答案

你没有使用 Realm 的 JSON 支持?如果是这样,您可以使用它,请参阅最后一项(我强调的):

Parsing JSON with Realm is subject to the following rules.

Creating object with JSON which has the field with a null value:

  • For a not-required field, set it to null which is the default value.
  • For a required field, throw an exception.
  • Updating object with JSON which has the field with a null value:
  • For a not-required field, set it to null.
  • For a required field, throw an exception.
  • JSON doesn’t have the field: Leave the value unchanged for both required and not-required fields.

来源: https://realm.io/docs/java/latest/#json

关于android - Realm - 跳过以编程方式编写嵌套对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35970688/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com