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
ContextValueFilter
wenshao edited this page Apr 19, 2016
·
6 revisions
在某些场景下,对Value做过滤,需要获得所属JavaBean的信息,包括类型、字段、方法等。在fastjson-1.2.9中,提供了ContextValueFilter,类似于之前版本提供的ValueFilter,只是多了BeanContext参数可用。
package com.alibaba.fastjson.serializer;
public interface ContextValueFilter extends SerializeFilter {
Object process(BeanContext context,
Object object,
String name,
Object value);
}
其中SerializeContext的定义如下:
package com.alibaba.fastjson.serializer;
public final class BeanContext {
public Class<?> getBeanClass();
public Method getMethod();
public Field getField();
public String getName();
public String getLabel();
public <T extends Annotation> T getAnnation(Class<T> annotationClass);
}
ContextValueFilter valueFilter = new ContextValueFilter() {
public Object process(SerializeContext context,
Object object,
String name,
Object value) {
Class<?> objectClass = context.getBeanClass();
UrlIdentify annotation = context.getAnnation(UrlIdentify.class);
// ....
return value;
}
};
JSON.toJSONString(model, valueFilter);
如有需要修改本注脚,请联系阿里巴巴,
© 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