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.
This is the conventional output of Jackson based on the name of the getter methods. Use the @JsonProperty annotation to override this behavior.