0

I am using ObjectMapper class to convert java bean class to json.

Output is comming in {"memberList":[{"id":"4","member":"Saurabh K","dob":"31/12/2012"}]}format.

I want key id as Id(Mean Capital I).

My Bean Class is:-

class MemberClass implements Serializable{ 
private static final long serialVersionUID = 1L; 
private Long Id;enter code here 
private String member; 
private Date dob; } 
MemberClass member = new MemberClass(); //some value set in to class variable ObjectMapper mapper = new ObjectMapper(); 
try {enter code here returnStr += mapper.writeValueAsString(member ); } 
catch (IOException e) { e.printStackTrace(); }
George Stocker
  • 57,289
  • 29
  • 176
  • 237
  • 2
    Could you please format your question? It is unreadable. –  Jun 04 '13 at 08:21
  • possible duplicate of [Different names of JSON property during serialization and deserialization](http://stackoverflow.com/questions/8560348/different-names-of-json-property-during-serialization-and-deserialization) – seanhodges Jun 04 '13 at 08:25
  • @Tichodroma : He is new... you could have done that... – Fahim Parkar Jun 04 '13 at 08:39

1 Answers1

3

If I understood your correctly you want to map bean property id to JSON property Id. If it is correct you can use @JsonProperty() annotation as following:

@JsonProperty("Id")
private Long id;

However take into consideration that this is against the widely used naming convention: property names should start with small letter.

AlexR
  • 114,158
  • 16
  • 130
  • 208