We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
在某些场景下,对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);