0

I have a Javascript application that uses Java as a backend with Hibernate, Spring and MySQL. The problem is that even though I have capitalized column in my DB, as well as in my entity source I'm getting lowercase column names in the JSON returned from the backend.

Here's the model source :

package app.model; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.Table; import org.codehaus.jackson.annotate.JsonAutoDetect; @JsonAutoDetect @Entity @Table(name="resources") public class Resource { @Id @GeneratedValue @Column(name="Id") private int Id; @Column(name="Name", nullable=false) private String Name; public int getId() { return Id; } public void setId(int id) { this.Id = id; } public String getName() { return Name; } public void setName(String name) { this.Name = name; } } 

And the returned JSON :

{"data":[{"name":"Tom","id":8},{"name":"Mike","id":9},{"name":"Jerry","id":10},{"name":"Larry","id":11},{"name":"Tina","id":12},{"name":"Tony","id":15}],"success":true}

Is this behaviour somehow overridable/configurable ? If anything more is needed I'll update the post with required data.

2 Answers 2

3

This is the conventional output of Jackson based on the name of the getter methods. Use the @JsonProperty annotation to override this behavior.

Sign up to request clarification or add additional context in comments.

Comments

3

try this..

@JsonProperty("Id") public int getId() { return Id; } public void setId(int id) { this.Id = id; } @JsonProperty("Name") public String getName() { return Name; } public void setName(String name) { this.Name = name; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.