I need to consume an API which returns pages of objects using Spring RestTemplate. The problem is that the name of the JSON page property which holds the collection of objects is dynamic. How can I map this dynamic JSON prop to its static counterpart in my POJO?
Here's the pojo:
public class DTO<T> {
private List<T> items;
public List<T> getItems() {
return items;
}
public DTO<T> setItems(List<T> items) {
this.items = items;
return this;
}
}
Here's two examples of JSON:
{
"forms": [{},{},{}]
}
{
"submissions": [{},{},{}]
}
In the former case I need to map JSON forms onto POJO's items, in the latter - submissions onto items. How do I go about that?