【发布时间】:2016-02-28 11:49:16
【问题描述】:
我使用Moshi 反序列化以下 JSON 文件:
{
"display": "Video 1",
"isTranslated": false,
"videoSize": [
1920,
1080
]
}
...使用以下模型类:
public class Stream {
public final String display;
public final boolean isTranslated;
public final int[] videoSize;
public Stream(String display,
boolean isTranslated,
int[] videoSize) {
this.display = display;
this.isTranslated = isTranslated;
this.videoSize = videoSize;
}
}
这按预期工作。
现在,我想替换 int[] 为专用的 VideoSize 类,该类将两个整数值映射到命名字段,例如:
public class VideoSize {
public final int height;
public final int width;
public VideoSize(int width, int height) {
this.height = height;
this.width = width;
}
}
custom type adapter 或其他方式可以做到这一点吗?
【问题讨论】:
标签: java json json-deserialization moshi