mardi 19 juillet 2016

Converting nested fields of JSON into java objects

Following is my class

class Feed {
    Long id;
    String title;
    String text;
    Short type;
    Object object;
}

Feed.object can be of any type based on Feed.type. When I upload the document of the class into elasticsearch every thing works fine, however, when the document is fetched back then org.codehaus.jackson.map.ObjectMapper converts Feed.object in LinkedHashMap. Is there a way to get the actual object? The JSON string I get is of Feed.

Following is the conversion:

Feed feed = mapper.readValue(response.getHits().getHits()[0].getSourceAsString(), Feed.class);

Aucun commentaire:

Enregistrer un commentaire