Search code examples
androidjsonspringrestrestlet

How to convert raw JSON response data into an ArrayList of model objects using Spring for Android?


I'm learning spring for android with androidannotations and I'm having trouble casting JSON data received via HTTP Get to my model objects.

I have the following code:

myRestClient.getRestTemplate().getMessageConverters().add(new GsonHttpMessageConverter());
ArrayList liveMatches = myRestClient.getLiveMatchesForUser((long) user_id);

This response is actually just a JSON representation of a list of Match objects.

How can I convert this raw JSON response into an ArrayList<Match> object?

Thanks!


Solution

  • Here is what worked for me.

    I created a simple class which was just a wrapper of an ArrayList data structure.

    Something like:

    public class MatchesListWrapper {
    
    public ArrayList<Match> matches;
    
    public MatchesListWrapper(ArrayList<Match> matches) {
        this.matches = matches;
    }
    
    public ArrayList<Match> getMatches() {
        return matches;
    }
    
    public void setMatches(ArrayList<Match> matches) {
        this.matches = matches;
    }
    

    }