通常,您
Data可以对您的类进行注释以应用过滤器:
@JsonFilter("test")class Data {您已指定不能在类上使用批注。您可以使用混入来避免注释
Data类。
@JsonFilter("test")class DataMixIn {}必须在上指定Mixins
,
ObjectMapper并且您指定不想重新配置它。在这种情况下,您始终可以复制
ObjectMapper及其配置,然后修改副本的配置。这不会影响
ObjectMapper代码中其他地方使用的原始文件。例如
ObjectMapper myMapper = mapper.copy();myMapper.addMixIn(Data.class, DataMixIn.class);
然后用新的
ObjectMapper
String json = myMapper.writer(filterProvider).writevalueAsString(new Data());System.out.println(json); // output: {"data1":"value1"}


