0
我有以下Jsons:傑克遜合併JSON數組
{"loc":[{"b":3}]}
和
{"loc":[{"a":9}]}
如何使用傑克遜2.9.0將它們合併到
{"loc":[{"a":9, "b":3}]}
這是什麼我到目前爲止
public class Config {
@JsonMerge
public AB[] loc;
}
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AB {
public Integer a;
public Integer b;
protected AB() { }
public AB(int a0, int b0) {
a = a0;
b = b0;
}
}
ObjectMapper mapper = new ObjectMapper();
config = mapper.readValue(aposToQuotes("{'loc':[{'b':3}]}"), Config.class);
config = mapper.readerForUpdating(config).readValue(aposToQuotes("{'loc':[{'a':9}]}"));
結果是
{"loc":[{"b":3},{"a":9}]}
感謝
你有什麼試過的?你卡在哪裏? – shmosel
請檢查我編輯過的帖子。謝謝 – nqngo