利用fastjson的一些使用小记

//Json converter to object
TouBaoTXTpaicResponse touBaoTXTpaicResponse = JSON.parseObject(json.toJSONString(), TouBaoTXTpaicResponse.class, (ExtraProcessor) (object, key, value) -> {
if (object != null && object instanceof PolicyResponse) {
PolicyResponse response = (PolicyResponse) object;
if (response.getElPolicyAddress() != null) {
response.setElPolicyAddress(response.getElPolicyAddress().replaceAll("&", "&"));
object = response;
}
}
});


public static Object serializeFieldNameToUpAndGetObject(Object o) {

if (o == null) {
throw new IllegalArgumentException("参数为空!");
}


return JSON.parse(JSON.toJSONString(o, new PascalNameFilter() {

@Override
public String process(Object source, String name, Object value) {

//序列化json串的时候把所有字段的第一个字母大写
name = StringUtils.capitalize(name);

return super.process(source, name, value);
}

}).getBytes());

}
上一篇:Gson/Jackson/FastJson工具类


下一篇:关于fastjson