I try to parse JSON below with java Jackson library but I not able to get the value at level "ChannelType", "Address" and etc. It is because of value "endpoint123" & "endppoint456", which cause some problem for me. I try to google but can't find elsewhere. Would like some 1 expert here to assist. Thanks in advance.
{
"Message": {},
"ApplicationId": "aaa",
"CampaignId": "bbb",
"TreatmentId": "0",
"ActivityId": "ccc",
"ScheduledTime": "2021-04-07T08:43:16.406Z",
"Endpoints": {
"endpointa123": {
"ChannelType": "CUSTOM",
"Address": "bobby@abc.com.my",
"EndpointStatus": "ACTIVE",
"OptOut": "NONE",
"EffectiveDate": "2021-04-07T08:35:48.796Z",
"User": {
"UserAttributes": {
"Custom4": [
"data4"
],
"Custom3": [
"data3"
],
"Custom2": [
"data2"
],
"Custom1": [
"data1"
],
"Custom5": [
"data5"
]
}
},
"CreationDate": "2021-04-07T08:35:48.796Z"
},
"endpoint456": {
"ChannelType": "CUSTOM",
"Address": "fifis@abc.com.my",
"EndpointStatus": "ACTIVE",
"OptOut": "NONE",
"EffectiveDate": "2021-04-07T08:35:48.792Z",
"User": {
"UserAttributes": {
"Custom4": [
"data4"
],
"Custom3": [
"data3"
],
"Custom2": [
"data2"
],
"Custom1": [
"data1"
],
"Custom5": [
"data5"
]
}
},
"CreationDate": "2021-04-07T08:35:48.792Z"
}
}
}
My code as per below, Campaign is my own define class.
Campaign campaign = mapper.readValue(json, Campaign.class);
String valueOut = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(campaign);
System.out.println(valueOut);
My Java Object Model for the above as per below.
Campaign
|--EndPoints
|-- EndPointsContainer (Array)
|--User
|--UserAttributes
Following is result which I get.
"Message" : { },
"ApplicationId" : "aaa",
"CampaignId" : "bbb",
"TreatmentId" : "0",
"ActivityId" : "ccc",
"ScheduledTime" : "2021-04-07T10:44:27.598Z",
"EndPoints" : {
"endPointsContainer" : [ ],
"creationDate" : null,
"CreationDate" : null
Thanks for @Robert. It at least quite similar with original JSON. POJO was reconstruct as per below.
Campaign
|--EndPoints
|--User
|--UserAttributes
However, CreationDate is inside object "endpoint123" and "endpoint456", instead of outside. Because it is lengthy. I posted part of it.
"ScheduledTime": "2021-04-07T08:43:16.406Z",
"Endpoints": {
"endpointa123": {
"CreationDate": "2021-04-07T08:35:48.796Z"
"ChannelType": "CUSTOM",