我的答復如下
[
{
"segmentId"。"Source_2021-09-01_2021-10-01",
"columns": [
" merchantRefNum",
"customerId",
"firstName",
],
"events": [
{
" merchantRefNum": "67456456",
"customerId": rfgvkhbj,
"firstName": "peter",
},
{
" merchantRefNum": "654584856",
"customerId": null。
"firstName": "peter"。
}
]
}
]
我想把這個json映射到一個POJO物件,并創建了這個類
public class MyClass {
private String segmentId;
private List<String> columns;
private List<KeyValuePair> events。
public static class KeyValuePair {
Map<String, String> 事件。
}
}
我目前是用這種方式來閱讀的
List<MyClass> responses = new ObjectMapper()。 readValue(jsonString,new TypeReference<List<MyClass>> (){})。
事件的大小是2,但每個事件都是空的,而不是一個地圖。
有人能幫助我嗎?
uj5u.com熱心網友回復:
為了實作你的目標,你必須對你的JSON進行如下調整:
[
{
"segmentId":"Source_2021-09-01_2021-10-01",
"columns":[
" merchantRefNum",
"customerId",
"firstName""events":[
{
"event":{
" merchantRefNum":"67456456"。
"customerId":"rfgvkhbj"。
"firstName":"peter"。
}
},
{
"event":{
" merchantRefNum":"654584856"。
"customerId":null。
"firstName":"peter"。
}
}
]
}
]
注意到已經添加的event欄位。
或者,改變你的DTO,就像這樣:
class MyClass {
private String segmentId;
private List<String> columns;
private List<Map<String, String> > events。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/322782.html
標籤:
