I am trying to find a clean way of parsing nested properties from a payload from an API
.
Here is a rough generalisation of the JSON
payload:
{
"root": {
"data": {
"value": [
{
"user": {
"id": "1",
"name": {
"first": "x",
"last": "y"
}
}
}
]
}
}
}
My goal is to have an array of User
objects which have firstName
and lastName
fields.
Does anyone know a good way to parse this cleanly?
Right now I am trying to create a Wrapper
class and within that have static inner classes for data, value, user etc. but this seems like a messy way of doing this just to read the array of first/last properties.
I am using restTemplate.exchange()
to call the endpoint.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…