springmvc bean转json,当bean的属性值为null时,过滤json对应字段
com.fasterxml.jackson.databind.ser.BeanPropertyWriter
@Override
public void serializeAsField(Object bean, JsonGenerator gen, SerializerProvider prov) throws Exception
{
// inlined 'get()'
final Object value = (_accessorMethod == null) ? _field.get(bean) : _accessorMethod.invoke(bean);
// Null handling is bit different, check that first
if (value == null) {
if (_nullSerializer != null) { // <<<<<================ _nullSerializer == null 就可以实现当bean的属性值为null时,json中对应字段不存在
gen.writeFieldName(_name);
_nullSerializer.serialize(null, gen, prov);
}
return;
}
。。。。
}
如何在spring.xml中配置实现?