私は、(私が受け取った)jsonドキュメントをJavaオブジェクトにマップするPOJOクラスを持っています。同じPOJOクラスのさまざまな出力のカスタムアノテーションを作成します
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public class Product implements Serializable, UniqueKeyAware {
private static final long serialVersionUID = -7311148654827944888L;
@JsonIgnore
private String uniqueKey;
@JsonProperty("uniqueKey")
private String uniqueKeyV2;
@JsonProperty("gtin")
private String gtin;
@JsonProperty("printedGtin")
private String printedGtin;
@JsonProperty("tpnb")
private String tpnb;
@JsonProperty("tpnc")
private String tpnc;
@JsonProperty("tpna")
private String tpna;
@JsonProperty("itemNumber")
private String itemNumber;
@JsonProperty("catId")
private String catId;
@JsonProperty("styleCode")
private String styleCode;
@JsonProperty("description")
private String description;
@JsonProperty("brand")
private String brand;
@JsonProperty("isOwnLabel")
private Boolean isOwnLabel;
@JsonProperty("regulatedProductName")
private String regulatedProductName;
@JsonProperty("country")
private List<Country> region;
... // remove for simplicity
私が望むのは、jsonから4つの別々のドキュメントを作成する最良の方法です。
したがって、このpojoクラスのサブセットである4つのクラスを定義できます。
- 公開
- プライベート
- パートナー
- Priviledge
コンフィギュラの目的のために、私は@public、@private、@partner、私は上記の書き込みを行います@priviledgeのようなカスタム注釈を必要としますすべてのフィールド。実行時に、例えば、 @publicアノテーションが記述されているフィールドだけのインスタンスが作成されます。
これを実装する必要があります。私はこれがジャックソンのライブラリにいくつかのフックを作成することによって可能だと思います。私は一日でそれをする必要があります、誰もちょうどこれを行う方法を指導することができます。
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonAutoDetect(fieldVisibility = ANY, getterVisibility = NONE, setterVisibility = NONE)
public class Product implements Serializable, UniqueKeyAware {
private static final long serialVersionUID = -7311148654827944888L;
@JsonIgnore
private String uniqueKey;
@JsonProperty("uniqueKey") @public @private
private String uniqueKeyV2;
@JsonProperty("gtin") @public
private String gtin;
@JsonProperty("printedGtin") @public
private String printedGtin;
@JsonProperty("tpnb")@private
private String tpnb;
@JsonProperty("tpnc")@private
private String tpnc;
@JsonProperty("tpna")@priviledge
private String tpna;
... // removed for simplicity
上記例えば中:
最終生成物は、これを好むべきです@ publicインスタンスは、属性としてuniqueKey、gtin、およびprintGtinを持ちます。