I have used Spring and the GsonHttpMessageConverter to auto parse my JSON objects into their respective models. I have gotten this to work with the following JSON:
{
"site_id" : "1234567",
"address" : "123 FAKE ST., City, State Zip",
"phone_number" : "5555555555"
}
My problem is with the api I am hitting with regards to arrays of sites like this:
{
"results" : [
{
"site_id" : "1234567",
"address" : "123 FAKE ST., City, State Zip",
"phone_number" : "5555555555"
}
]
}
What I would like to parse from that response is just an array of site objects but because the array is nested inside the “results” object I’m not sure how to do this. Is there a way of using the GsonHttpMessageConverter with Spring to accomplish this?
I found the answer I was looking for. To accomplish the auto parsing for the nested json list I had to nest my objects inside another object and pass that to the Spring networking library. Here is the resulting top level model needed: