带有include/exclude属性的JSONView注释

har*_*rsh 5 java json jackson

我有一个用例,其中使用带有排除信息的JSONView注释似乎更合适,例如:

@JSONView(Views.Report1.class, include=false)
Run Code Online (Sandbox Code Playgroud)

这不是杰克逊(1.9.2)直接支持的(包括属性),因为我想知道杰克逊是否有一个简单的解决方法来实现这一目标.

使用案例:

  • Report1:此视图应具有id, name, info1, info2, info3, info4属性
  • Report2:此视图应具有id, name, info1, info2, info4属性
  • 报告[3 ..]说许多其他观点是可能的
private int id;
  private String name;
  private String info1;
  private String info2;
  //ignore if view=report2
  @JsonView(ReportViews.Report2.class , include=false)
  private String info3;
  private String info4;

我的用例是根据视图(或者说report-ids)排除属性.使用JSONView方法,我需要将所有视图添加到除Report2之外的info3属性以将其排除.不合适.

在这种情况下,正确的方法应该是什么?定制JSONView除了排除/包含将是正确的解决方案,如果没有类似的已经可用.

Sta*_*Man 1

Jackson 的 JSON 视图功能基于包含标准,因此您无法更改现有注释。