2017-08-15 119 views
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}]} 

感謝

+0

你有什麼試過的?你卡在哪裏? – shmosel

+0

請檢查我編輯過的帖子。謝謝 – nqngo

回答

-1

首先,你可以將JSON的ConvertTo列表和合並列表,然後將列出的ConvertTo JSON。