【发布时间】:2012-06-05 14:09:08
【问题描述】:
我正在使用 Google GSON 将我的 Java 对象转换为 JSON。
目前我的结构如下:
"Step": {
"start_name": "Start",
"end_name": "End",
"data": {
"duration": {
"value": 292,
"text": "4 min."
},
"distance": {
"value": 1009.0,
"text": "1 km"
},
"location": {
"lat": 59.0000,
"lng": 9.0000,
"alt": 0.0
}
}
}
目前Duration 对象位于Data 对象内。我想跳过Data 对象并将Duration 对象移动到Step 对象,如下所示:
"Step": {
"start_name": "Start",
"end_name": "End",
"duration": {
"value": 292,
"text": "4 min."
},
"distance": {
"value": 1009.0,
"text": "1 km"
},
"location": {
"lat": 59.0000,
"lng": 9.0000,
"alt": 0.0
}
}
如何使用 GSON 做到这一点?
编辑:我尝试使用 TypeAdapter 来修改 Step.class,但在 write-method 中我无法将我的持续时间对象添加到 JsonWriter。
【问题讨论】: