杰克逊仍然抱怨缺少过滤器 ID / 跳过丢失的过滤器
Jackson still complains about missing filter id / skip missing filters
我有一个像这样的 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)
但是当我序列化 jackson 时仍然抱怨缺少过滤器 ID 并且失败了。我如何为特定的映射器重新添加缺少的过滤器?
信不信由你,你必须在模块之后设置过滤器
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)
我有一个像这样的 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)
但是当我序列化 jackson 时仍然抱怨缺少过滤器 ID 并且失败了。我如何为特定的映射器重新添加缺少的过滤器?
信不信由你,你必须在模块之后设置过滤器
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)