FasterXML / jackson-annotations

Core annotations (annotations that only depend on jackson-core) for Jackson data processor
https://github.com/FasterXML/jackson
Apache License 2.0
1.03k stars 330 forks source link

FEATURE: Allow to specify a Json View to serialize a property of an object #132

Open ccasallas opened 6 years ago

ccasallas commented 6 years ago

Currently it's not possible to serialize the property of an object specifying a Json view. Please create a new @JsonUseView annotation to be able to specify a view used to serialize the property.

public class Company {
  @JsonView(View.Basic.class)
  private Long id;

  @JsonView(View.Basic.class)
  private String name;

  private String extraData;
  private String sensitiveData;
  private String privateData;
  ...
}

public class User{
  private Long id;
  private String name;

  @UseJsonView(View.Basic.class)
  private Company company;
  ...
}

Or create a new set of annotations that allow this feature. For example:

@JsonViews(views={
  @View(name="basic", fields=["id", "name"]),
  @View(name="otherView", fields=["id", "name", "extraData"]),
})
public class Company {
  private Long id;
  private String name;
  private String extraData;
  private String sensitiveData;
  private String privateData;
  ...
}

public class User{
  private Long id;
  private String name;

  @UseJsonView("basic")
  private Company company;
  ...
}
lenxeon commented 4 years ago

what the content about UseJsonView ?