0
我正在解析類爲JSON Apple Push Notification Service。所以我有一個ApnsPayload
類,並希望將最終的JSON附加到額外的,可選的和動態的acme
屬性。這意味着我需要將以下傑克遜輸出轉換...Jackson Json序列化程序追加內部屬性
{
"aps": {
"alert": {
"body": "body",
"title": "title"
},
"badge": 123,
"category": "category"
},
"acme": {
"1": "1",
"value1": "value1"
}
}
要這個......
{
"aps": {
"alert": {
"body": "body",
"title": "title"
},
"badge": 123,
"category": "category"
},
"acme-1": "1",
"acme-value1": "value1"
}
我已經成功添加一個前綴acme-
那些鍵與@JsonNaming()
,但我不能搬完屬性一級。請幫忙,謝謝!
@Value
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
// need a serializer to move up properties in Acme by one level
// @JsonSerialize(using = NewSerializer.class)
public class ApnsPayload {
private Aps aps;
private Acme acme;
@JsonNaming(AcmeNamingStrategy.class) // add prefix acme-
public interface Acme {
}
@Value
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Aps {
private Alert alert;
private Integer badge;
private String sound;
@JsonProperty("content-available")
private Integer contentAvailable;
private String category;
@JsonProperty("thread-id")
private String threadId;
@Value
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Alert {
private String title;
private String body;
@JsonProperty("title-loc-key")
private String titleLocalizationKey;
@JsonProperty("title-loc-args")
private List<String> titleLocalizationArgs;
@JsonProperty("action-loc-key")
private String actionLocalizationKey;
@JsonProperty("loc-key")
private String localizationKey;
@JsonProperty("loc-args")
private List<String> localizationArgs;
@JsonProperty("launch-image")
private String launchImage;
}
}
}