Issue
Seeing the exception when I call the GET method in RestTemplate
com.fasterxml.jackson.databind.JsonMappingException: N/A at [Source: (StringReader); line: 1, column: 13700] (through reference chain: com.homedepot.merch.meter.model.ResultSet["issues"]->java.util.ArrayList[0]->com.homedepot.merch.meter.model.Issue["fields"])
the sample java code is
ResponseEntity<String> response = restTemplate.exchange(JIRA_URL, HttpMethod.GET, entity, String.class);
ObjectMapper jsonMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
if(response != null && response.getStatusCode() == HttpStatus.OK) {
ResultSet resultSet = jsonMapper.readValue(response.getBody(), ResultSet.class);
List<Issue> issues = resultSet.getIssues();
}
java classses are
@Data
public class ResultSet {
private int startAt;
private int maxResults;
private int total;
private List<Issue> issues;
}
and the Issue class definition is
@Data
public class Issue {
private String teamid;
private String jiraboardid;
@JsonAlias("id")
private int id;
@JsonAlias("key")
private String issueid;
private String issuetype;
//private Sprint sprint;
private int sprintId;
private String sprintname;
private Timestamp sprintstartdate;
private Timestamp sprintenddate;
private String state;
private String status;
private String createddate;
private String creator_emailAddress;
private String creator_displayName;
private String creator_accountId;
private boolean creator_isActive;
private String inprogressdate;
private String developmentdate;
private String completeddate;
private double developmentleadtime;
private double leadtime;
private String statuscategorychangeddate;
private String lastupdateduser;
private String lastupdateddate;
private Double issuepoints;
private ChangeLog changelog;
@JsonProperty("fields")
private void unpackNameFromNestedObject(Map<String, Object> brand) throws ParseException, JSONException, InterruptedException {
createddate = brand.get("created").toString();
statuscategorychangeddate = brand.get("statuscategorychangedate").toString();
lastupdateddate = brand.get("updated").toString();
issuetype = objectToString(brand.get("issuetype"), "issuetype");
status = objectToString(brand.get("status"), "status");
lastupdateduser = objectToString(brand.get("assignee"), "assignee");
developmentdate = getIssueDevelopmentDoneTime(getChangelog().getHistories());
if (brand.get("resolutiondate") != null) {
completeddate = brand.get("resolutiondate").toString();
}else
completeddate = getIssueDoneTime(getChangelog().getHistories());
if (brand.get("customfield_10025") != null)
issuepoints = Double.parseDouble(brand.get("customfield_10025").toString());
else
issuepoints = 0.0;
inprogressdate = getIssueInProgressTime(getChangelog().getHistories());
if (inprogressdate != null && completeddate != null)
leadtime = findDifference(inprogressdate, completeddate);
if (inprogressdate != null && developmentdate != null)
developmentleadtime = findDifference(inprogressdate, developmentdate);
else
developmentleadtime = leadtime;
//If there's no Done status, assign developmentleadtime for leadtime
if (developmentdate != null && completeddate == null)
leadtime = developmentleadtime;
try{
creator_emailAddress = objectToCreator(brand.get("creator"), "emailAddress");
}catch (Exception ex){
System.out.println(issueid+ " Exception :"+ex);
}
creator_displayName = objectToCreator(brand.get("creator"), "displayName");
creator_accountId = objectToCreator(brand.get("creator"), "accountId");
creator_isActive = Boolean.parseBoolean(objectToCreator(brand.get("creator"), "isActive"));
}
}
How do I fix this JsonMappingException?
Solution
You are trying to serialize the result of a method that returns void. Also, I am not sure if private access methods can be serialized. I think that serialization methods are not supposed to get parameters, typically they are getters.
Answered By - orestis
Answer Checked By - Marilyn (JavaFixing Volunteer)