我测试了下,目前json下划线直接可以用驼峰式的对象接收的。但是我想驼峰式的对象转成下划线的json,检查了SerializerFeature里面也没找到,最后只能自定义NameFilter 类似于下面的代码,到时候怕效率问题。
String str = JSON.toJSONString(b, new NameFilter() {
@Override
public String process(Object object, String name, Object value) {
Matcher matcher = humpPattern.matcher(name);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
});
现在fastjson 是否有更快捷的方式 实现驼峰式转下划线的。
非常感谢
Most helpful comment
看这个是否能满足你的需求:
https://github.com/alibaba/fastjson/wiki/PropertyNamingStrategy_cn