本文介绍了使用杰克逊解析领域模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用杰克逊库将领域模型转换为json对象时获取未知密钥.
Getting unknown key while converting realm model into json object using jackson library.
这是我的领域模型实例.
Here is my realm model instance.
public class RecordData extends RealmObject {
public RecordData() {
}
private FormData formData;
@Nullable
@JsonProperty("values")
private RealmList<Values> values;
@Nullable
@JsonProperty("value")
private String value;
}
用于将领域模型转换为json对象的代码.
Code for converting realm model to json object.
JSONObject recordDataJsonObject = new JSONObject(new ObjectMapper().writeValueAsString(formData.getRecordData()));
解析json的输出:
{"loaded":true,"managed":false,"valid":true,"value":"fdfdf","values":[]}
领域版本:io.realm:realm-gradle-plugin:4.1.1
Rxjava版本:'io.reactivex.rxjava2:rxjava:2.1.6'
Rxjava version : 'io.reactivex.rxjava2:rxjava:2.1.6'
Jackson版本:com.fasterxml.jackson.core:jackson-databind:2.8.6
Jackson version : com.fasterxml.jackson.core:jackson-databind:2.8.6
为什么我要加载,管理和有效的布尔值?
Why i am getting loaded, managed and valid boolean values ?
推荐答案
您可以使用@JsonIgnoreProperties
批注:
@JsonIgnoreProperties({"loaded", "managed", "valid"})
public class RecordData extends RealmObject {
public RecordData() {
}
private FormData formData;
@Nullable
@JsonProperty("values")
private RealmList<Values> values;
@Nullable
@JsonProperty("value")
private String value;
}
另一种选择是使用@RealmClass public class RecordData implements RealmModel
.
这篇关于使用杰克逊解析领域模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!