Fastjson: 关于驼峰式、下划线互转

Created on 20 Mar 2017  ·  2Comments  ·  Source: alibaba/fastjson

我测试了下,目前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 是否有更快捷的方式 实现驼峰式转下划线的。

question

Most helpful comment

All 2 comments

非常感谢

Was this page helpful?
0 / 5 - 0 ratings