0
votes

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(); }
1
Could you please format your question? It is unreadable.user1907906
@Tichodroma : He is new... you could have done that...Fahim Parkar

1 Answers

3
votes

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.