Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 6.4k
Class_Level_SerializeFilter
高铁 edited this page Aug 11, 2017
·
3 revisions
对于框架来说,如果在toJSONString的时候,传入SerializeFilter,会导致对所有的类型做过滤,性能会受到一定影响。在1.2.10版本之后,fastjson提供类级别的SerializeFilter支持。
1.2.10 and later
packagecom.alibaba.fastjson.serializer;
publicclassSerializeConfig {
publicvoidaddFilter(Class<?> clazz, SerializeFilterfilter);
}publicclassClassNameFilterTestextendsTestCase {
publicvoidtest_filter() throwsException {
NameFilterupcaseNameFilter = newNameFilter() {
publicStringprocess(Objectobject, Stringname, Objectvalue) {
returnname.toUpperCase();
}
};
SerializeConfig.getGlobalInstance() //
.addFilter(A.class, upcaseNameFilter);
Assert.assertEquals("{\"ID\":0}", JSON.toJSONString(newA()));
Assert.assertEquals("{\"id\":0}", JSON.toJSONString(newB()));
}
publicstaticclassA {
publicintid;
}
publicstaticclassB {
publicintid;
}
}如有需要修改本注脚,请联系阿里巴巴,
© Alibaba Fastjson Develop Team
注明: 版权所有阿里巴巴,请注明版权所有者
If you need to amend this footnote, please contact Alibaba.
© Alibaba Fastjson Develop Team
Note: Copyright Alibaba, please indicate the copyright owner