GSON: Cómo mover campos al objeto padre
Estoy usandoGoogle GSON para transformar mi objeto Java a JSON.
Actualmente tengo la siguiente estructura:
"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
}
}
}
Actualmente unDuration
objeto está dentro de unData
objeto. Me gustaria saltarme elData
objetar y mover elDuration
objetar alStep
Objeto, como este:
"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
}
}
¿Cómo puedo hacer esto usando GSON?
EDITAR: He intentado usar un TypeAdapter para modificar el Step.class, pero en el método de escritura no puedo agregar mi objeto de duración al JsonWriter.