Reputation: 95
I am facing one issue. Jackson mapping missing one key value to map POJO class.
Using this maven dependancy -
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>
This is the code -
try {
ObjectMapper mapper = new ObjectMapper();
allGroupResponse = mapper.readValue(record, AllGroupResponse.class);
} catch (Exception e) {
e.printStackTrace();
}
A POJO Class
public class AllGroupResponse {
private String status;
private String data;
private String message;
private String tag;
private List<GroupTable> groupListDTO;
}
public class GroupTable {
private String id;
private String groupId;
private String groupName;
private String address;
private String groupLimit;
private String groupPairingCode;
private String zoneId;
private String siteContactNumber;
private String programId;
private String projectId;
private String createdBy;
private String updatedBy;
private String partyProfileId;
private String groupType;
private Date createdDate;
private Date updatedDate;
private Date groupPairingValidity;
private String groupManagerName;
private String groupManagerEmail;
private List<String> userEmailIds;
private String description;
private String status;
private String city;
private String state;
private String parentReference;
}
This is JSON string -
{
"data": null,
"groupListDTO": [
{
"groupType": "PARENT",
"city": null,
"groupId": "demo site_39329fbf-97ce-4474-bfab-db0f00ffa4b9",
"description": null,
"updatedDate": 1562310647155,
"parentReference": "null",
"zoneId": "demotest-zone_13f74715-fad9-4517-9cbd-bd47fa7c4df7",
"id": "0cab0526-ce7c-4cd8-80cd-77e1e7e52b29",
"state": null,
"groupLimit": null,
"address": "Mu",
"updatedBy": "[email protected]",
"groupManagerEmail": null,
"groupPairingCode": null,
"groupManagerName": null,
"groupName": "Demo Site",
"createdDate": 1557490542612,
"createdBy": null,
"groupPairingValidity": null,
"partyProfileId": null,
"siteContactNumber": "",
"projectId": "ab4dafed-7fd9-46c0-ab9a-b28d756c4f11",
"programId": null,
"userEmailIds": ["[email protected]"],
"status": "UPDATED"
}
],
"tag": "GROUP_LIST_FOUND",
"message": "Get all the group list for user.",
"status": "SUCCESS"
}
After mapping to the POJO Class. Printed toString -
AllGroupResponse{status='SUCCESS', data='null', message='Get all the group list for user.', tag='GROUP_LIST_FOUND', groupListDTO=[GroupTable{id='0cab0526-ce7c-4cd8-80cd-77e1e7e52b29', groupId='demo site_39329fbf-97ce-4474-bfab-db0f00ffa4b9', groupName='Demo Site', address='Mu', groupLimit='null', groupPairingCode='null', zoneId='demotest-zone_13f74715-fad9-4517-9cbd-bd47fa7c4df7', siteContactNumber='', programId='null', projectId='ab4dafed-7fd9-46c0-ab9a-b28d756c4f11', createdBy='null', updatedBy='[email protected]', partyProfileId='null', groupType='PARENT', createdDate=Fri May 10 17:45:42 IST 2019, updatedDate=Fri Jul 05 12:40:47 IST 2019, groupPairingValidity=null, groupManagerName='null', groupManagerEmail='null', userEmailIds=[[email protected]], description='null', status='UPDATED', city='null', state='null'}]}
Here I found the key "parentReference": "null"
is missing. I understand the value null is in string format. But it should map as it is considered String.
I don't understand why it is happening. There is no exception occurred. Please let me know the solution.
Upvotes: 1
Views: 593
Reputation: 95
Forgot to add updated parameter in toString() method - Thanks @alexey28
@Override
public String toString() {
return "GroupTable{" +
"id='" + id + '\'' +
", groupId='" + groupId + '\'' +
", groupName='" + groupName + '\'' +
", address='" + address + '\'' +
", groupLimit='" + groupLimit + '\'' +
", groupPairingCode='" + groupPairingCode + '\'' +
", zoneId='" + zoneId + '\'' +
", siteContactNumber='" + siteContactNumber + '\'' +
", programId='" + programId + '\'' +
", projectId='" + projectId + '\'' +
", createdBy='" + createdBy + '\'' +
", updatedBy='" + updatedBy + '\'' +
", partyProfileId='" + partyProfileId + '\'' +
", groupType='" + groupType + '\'' +
", createdDate=" + createdDate +
", updatedDate=" + updatedDate +
", groupPairingValidity=" + groupPairingValidity +
", groupManagerName='" + groupManagerName + '\'' +
", groupManagerEmail='" + groupManagerEmail + '\'' +
", userEmailIds=" + userEmailIds +
", description='" + description + '\'' +
", status='" + status + '\'' +
", city='" + city + '\'' +
", state='" + state + '\'' +
", parentReference='" + parentReference + '\'' +
'}';
}
Upvotes: 1