一、定义Student实体类,包含如下字段
public class Student {
private String name;
private Integer age;
private Date date;
@JSONField(name = "order_no")
private String orderNo;
@JSONField(name = "order_no2")
private String orderNo2;
...省略get、set方法
}
二、可以定义ObjectMapper进行转换
MAPPER2.setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE);
//1. 定义mapper对象
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final ObjectMapper MAPPER2 = new ObjectMapper();
static {
//如果是空对象的时候,不抛异常
MAPPER2.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
MAPPER2.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)