springboot实战电商项目mall4j (https://gitee.com/gz-yami/mall4j)
环境:jdk1.8
系统:window/linux
fastjson版本:1.2.29
关键代码:
public class FastJsonUtil {
/*
* 将 pojo 对象转为 json 字符串,并且驼峰命名修改为下划线命名
*/
public static String buildData(Object bean) {
try {
SerializeConfig config = new SerializeConfig();
config.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
return JSON.toJSONString(bean, config);
} catch (Exception e) {
return null;
}
}
}
// 随意的一个实体类
public class T {
public String userName;
public String userArg;
public String userGender;
public String userAddr;
public T(String userName, String userArg, String userGender, String userAddr) {
this.userName = userName;
this.userArg = userArg;