lundi 20 avril 2015

How to map JSON fields to custom object properties?

I have a simple json message with some fields, and want to map it to a java object using spring-web.

Problem: my target classes fields are named differently than int he json response. How can I anyhow map them to the object without having to rename the fields in java?

Is there some annotation that could be placed here?

{
  "message":"ok"
}

public class JsonEntity {
    //how to map the "message" json to this property?
    private String value;
}

RestTemplate rest = new RestTemplate();
rest.getForObject(url, JsonEntity.class);

Aucun commentaire:

Enregistrer un commentaire