杰克逊仍然抱怨丢失过滤器ID /跳过丢失的过滤器

时间:2015-03-04 14:30:09

标签: java json jackson

我有一个像这样的ObjectMapper:

ObjectMapper mapper = new ObjectMapper();

// ignore missing filters
mapper.setFilters(new SimpleFilterProvider().setFailOnUnknownId(false));

// add module for meta data permissions
SimpleModule module = new SimpleModule("IncludeMetaData", new Version(0, 1, 0, "alpha"));
module.addSerializer(MetaClass.class, new MetaDataSerializer(permissions, p instanceof AbstractBean ? ((AbstractBean) p).isOwner() : false));
mapper.registerModule(module);

return mapper.writerWithView(Views.Admin.class).writeValueAsString(p)

但是当我序列化时,杰克逊仍抱怨丢失过滤器ID而失败。如何针对特定的映射器错过过滤器?

1 个答案:

答案 0 :(得分:0)

信不信由你,你必须在模块之后设置过滤器

ObjectMapper mapper = new ObjectMapper();

// add module for meta data permissions
SimpleModule module = new SimpleModule("IncludeMetaData", new Version(0, 1, 0, "alpha"));
module.addSerializer(MetaClass.class, new MetaDataSerializer(permissions, p instanceof AbstractBean ? ((AbstractBean) p).isOwner() : false));
mapper.registerModule(module);

// ignore missing filters
mapper.setFilters(new SimpleFilterProvider().setFailOnUnknownId(false));

return mapper.writerWithView(Views.Admin.class).writeValueAsString(p)