本文整理汇总了Java中com.fasterxml.jackson.databind.ObjectMapper.setFilterProvider方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectMapper.setFilterProvider方法的具体用法?Java ObjectMapper.setFilterProvider怎么用?Java ObjectMapper.setFilterProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.fasterxml.jackson.databind.ObjectMapper
的用法示例。
在下文中一共展示了ObjectMapper.setFilterProvider方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMapper
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
private ObjectMapper createMapper(JsonFactory mapping, ClassLoader classLoader) {
ObjectMapper mapper = new ObjectMapper(mapping);
mapper.addMixIn(MasterSlaveServersConfig.class, MasterSlaveServersConfigMixIn.class);
mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
mapper.addMixIn(Config.class, ConfigMixIn.class);
mapper.addMixIn(CodecProvider.class, ClassMixIn.class);
mapper.addMixIn(ResolverProvider.class, ClassMixIn.class);
mapper.addMixIn(Codec.class, ClassMixIn.class);
mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);
FilterProvider filterProvider = new SimpleFilterProvider()
.addFilter("classFilter", SimpleBeanPropertyFilter.filterOutAllExcept());
mapper.setFilterProvider(filterProvider);
mapper.setSerializationInclusion(Include.NON_NULL);
if (classLoader != null) {
TypeFactory tf = TypeFactory.defaultInstance()
.withClassLoader(classLoader);
mapper.setTypeFactory(tf);
}
return mapper;
}
示例2: outfitMetadataFilter
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
/**
* Outfit the given {@link ObjectMapper} with a filter that will treat all metadata map entries as transient.
*
* @param om object mapper to modify
*/
private static void outfitMetadataFilter(ObjectMapper om) {
final String filterName = "exclude-metadata";
SimpleFilterProvider filters = new SimpleFilterProvider();
filters.addFilter(filterName, new MetadataPropertyFilter());
om.setAnnotationIntrospector(new JsonWrapperIntrospector(filterName));
om.setFilterProvider(filters);
}
示例3: getErrorCode
import com.fasterxml.jackson.databind.ObjectMapper; //导入方法依赖的package包/类
@ExceptionHandler(CerebroException.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
public String getErrorCode(final CerebroException exception) throws IOException {
LOGGER.error("Service error", exception);
ObjectMapper objectMapper = new ObjectMapper();
FilterProvider filterProvider = new SimpleFilterProvider().addFilter("responseFilter",
SimpleBeanPropertyFilter.filterOutAllExcept("errorCode", "errorMessage"));
objectMapper.setFilterProvider(filterProvider);
return objectMapper.writeValueAsString(exception);
}