【问题标题】:Serialize an Array of Integers with a Serializable RealmObject使用可序列化的 RealmObject 序列化整数数组
【发布时间】:2019-08-12 07:15:27
【问题描述】:

我正在使用一个端点,它返回一个整数数组,指示我可以使用的允许支付类型,例如:

[0,1,2,3]

但是,我无法将其映射到列表中。我已经尝试过一个简单的整数列表。

@SerializedName("permitted_payment_types")
public List<Integer> paymentTypes;

我收到以下错误。

不支持的类型java.util.List&lt;java.lang.Integer&gt;

我已经尝试了RealmListRealmObjects,但没有成功。

@SerializedName("permitted_payment_types")
public RealmList<PaymentType> paymentTypes;

public class PaymentType extends RealmObject {
    public Integer type;
}

我在这里尝试了很多链接,但似乎都没有解决问题。

谁能给我一盏灯?

【问题讨论】:

    标签: java android realm serializable


    【解决方案1】:

    由于您的付款类型没有被任何对象包装,因此只需让代码中的 api 响应返回 List 而无需将其包装在对象内即可:

    List<Integer> getPaymentTypes()
    

    假设你正在使用改造

    【讨论】:

      【解决方案2】:

      其实只是

      RealmList<Integer> paymentTypes;
      

      它从 Realm 4.0.0 开始工作。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-03-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-11
        • 1970-01-01
        • 2016-01-28
        • 2018-06-26
        相关资源
        最近更新 更多