我正在使用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。