How to change a field name in JSON using Jackson

I’m using jackson to convert an object of mine to json.
The object has 2 fields:

@Entity
public class City {
   @id
   Long id;
   String name;
   public String getName() { return name; }
   public void setName(String name){ this.name = name; }
   public Long getId() { return id; }
   public void setName(Long id){ this.id = id; }
}

Since I want to use this with the jQuery auto complete feature I want ‘id’ to appear as ‘value’ in the json and ‘name’ to appear as ‘label’. The documentation of jackson is not clear on this and I’ve tried every annotation that even remotely seems like it does what I need but I can’t get name to appear as label and id to appear as value in the json.

Does anyone know how to do this or if this is possible?

4 Answers
4

Leave a Comment