Domanda

I'm getting a response from Elasticsearch in JSON format that I'd like Gson to convert into a Java class, however I'm having trouble wrapping my head about how to develop the class. Here's the JSON that is returned:

{
"took":3,
"_shards":{
    "total":3,
    "successful":3,
    "failed":0
},
"total":1,
"matches":[
    {
        "_index":"object_percolator",
        "_id":"2"
    },
    {
        "_index":"object_percolator",
        "_id":"3"
    }
]
}

The 'matches' is what is giving me a hard time. How would I design the class to handle that array? Any ideas? Thanks in advance!

È stato utile?

Soluzione

class Matches{
   List<MatchesCollection> matchCollection=new ArrayList<MatchesCollection>();
//add getter and setter here
}
      class MatchesCollection {
             private String _index;
             private Integer _id;
             //add getter and setter here
        }

//add the objects you need to be retrieved

Try to google about POJO

Check this link for creating classes How to create a POJO?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top