This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Class_Level_SerializeFilter
高铁 edited this page Aug 11, 2017
·
3 revisions
对于框架来说,如果在toJSONString的时候,传入SerializeFilter,会导致对所有的类型做过滤,性能会受到一定影响。在1.2.10版本之后,fastjson提供类级别的SerializeFilter支持。
1.2.10 and later
package com.alibaba.fastjson.serializer;
public class SerializeConfig {
public void addFilter(Class<?> clazz, SerializeFilter filter);
}
public class ClassNameFilterTest extends TestCase {
public void test_filter() throws Exception {
NameFilter upcaseNameFilter = new NameFilter() {
public String process(Object object, String name, Object value) {
return name.toUpperCase();
}
};
SerializeConfig.getGlobalInstance() //
.addFilter(A.class, upcaseNameFilter);
Assert.assertEquals("{\"ID\":0}", JSON.toJSONString(new A()));
Assert.assertEquals("{\"id\":0}", JSON.toJSONString(new B()));
}
public static class A {
public int id;
}
public static class B {
public int id;
}
}
如有需要修改本注脚,请联系阿里巴巴,
© 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