I'm retrieving a JSON string from an API using a RESTEasy client. The JSON payload looks something like this:
{
"foo1" : "",
"foo2" : "",
"_bar" : {
"items" : [
{ "id" : 1 , "name" : "foo", "foo" : "bar" },
{ "id" : 2 , "name" : "foo", "foo" : "bar" },
{ "id" : 3 , "name" : "foo", "foo" : "bar" },
{ "id" : 4 , "name" : "foo", "foo" : "bar" }
]
}
}
Now I'd like to extract only the items
node for object mapping. What is the best way to intercept the JSON response body and modify it to have items
as root node?
I'm using the RESTEasy proxy framework for my API methods.
The REST client code:
ResteasyWebTarget target = client.target("https://"+server);
target.request(MediaType.APPLICATION_JSON);
client.register(new ClientAuthHeaderRequestFilter(getAccessToken()));
MyProxyAPI api = target.proxy(MyProxyAPI.class);
MyDevice[] result = api.getMyDevice();
RESTEasy proxy interface:
public interface MyProxyAPI {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/device")
public MyDevice[] getMyDevices();
...
}