在使用jackson处理boolean类型的时候,比如你的java bean有一个boolean类型的字段:isTitle, 默认把这个Java bean
转换为json的时候,这个字段就变成了title,因此如果想在转换转换的json中保持原始的字段名称的话,可以在java bean中采用下面的例子进行处理:
也就是使用@JsonProperty和@JsonIgnore注解
public class User { private int id; @JsonProperty("isMale") private boolean isMale; private String name; public User() { } public User(int id, boolean isMale, String name) { this.id = id; this.isMale = isMale; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } @JsonIgnore public boolean isMale() { return isMale; } public void setMale(boolean isMale) { this.isMale = isMale; } public String getName() { return name; } public void setName(String name) { this.name = name; } }