【发布时间】:2019-09-25 04:35:04
【问题描述】:
我有一个 json,我在领域模型中通过注释 @SerializedName 使用 gson 进行转换。
但有时在 json 中有一个未知键,我想将其序列化为字符串。
public class example extend Realmobject{
@SerializedName("example1")
@Expose
private String exampleNr1;
@SerializedName("example2")
@Expose
private String exampleNr2;
private String someOtherValue;
Getter / Setter here...
}
Json 是这样的
[
{
"example1": "1234",
"example2": "1234",
"x": "dynamic"}, {
"example1": "1454",
"example2": "165456",
"xy": "dynamic"}]
现在我将序列化 x 和 xy 键(有时被命名为 xyz 等等)到 someOtherValue 字符串。 在@SerializedName(value="", alternate={""}) 我没有机会,因为,我不知道该字段的名称。
i 序列化这个 列表 woList = gson.fromJson(parentArray, new TypeToken>() {}.getType());
【问题讨论】: