0

I have the following JSON string

{
"_embedded": {
    "issues": [
        {
            "projectId": 1,
            "description": "description",
            "reason": "reason",
            "consequence": "consequence",
            "category": null,
            "severity": "HIGH",
            "priority": "HIGH",
            "source": "INTERN",
            "owner": "owner",
            "deadline": 1234567890,
            "cost": 0,
            "status": "OPEN",
            "versionNo": 0,
            "creationTimestamp": 1419255929860,
            "lastUpdateTimestamp": 1419255929860,
            "createdBy": "",
            "lastUpdatedBy": "",
            "_links": {
                "self": {
                    "href": "http://lcalhost:8080/im-access/api/issues/1"
                }
            }
        },
        {
            "projectId": 1,
            "description": "description",
            "reason": "reason",
            "consequence": "consequence",
            "category": null,
            "severity": "HIGH",
            "priority": "HIGH",
            "source": "INTERN",
            "owner": "owner",
            "deadline": 1234567890,
            "cost": 0,
            "status": "OPEN",
            "versionNo": 0,
            "creationTimestamp": 1418911336913,
            "lastUpdateTimestamp": 1418911336913,
            "createdBy": "",
            "lastUpdatedBy": "",
            "_links": {
                "self": {
                    "href": "http://lcalhost:8080/im-access/api/issues/2"
                }
            }
        },
        {
            "projectId": 1,
            "description": "description",
            "reason": "reason",
            "consequence": "consequence",
            "category": null,
            "severity": "HIGH",
            "priority": "HIGH",
            "source": "INTERN",
            "owner": "owner",
            "deadline": 1234567890,
            "cost": 0,
            "status": "OPEN",
            "versionNo": 0,
            "creationTimestamp": 1418911337383,
            "lastUpdateTimestamp": 1418911337383,
            "createdBy": "",
            "lastUpdatedBy": "",
            "_links": {
                "self": {
                    "href": "http://lcalhost:8080/im-access/api/issues/3"
                }
            }
        }
]
}
}

When I try to fetch the data, using

ObjectMapper objectMapper = new ObjectMapper();
List<IssueDTO> asList = objectMapper.readValue(new URL("http://lcalhost:8080/imaccess/api/issues"), objectMapper.getTypeFactory().constructCollectionType(List.class, IssueDTO.class));

I get org.codehaus.jackson.map.JsonMappingException: Can not deserialize instance of java.util.ArrayList out of START_OBJECT token.

I also tried to use RestTemplate and create a Wrapper class for the issues, but didn't have much luck with it either.

Gábor Bakos
  • 8,982
  • 52
  • 35
  • 52
user2791841
  • 71
  • 1
  • 9
  • 1
    Your code expects an array of issues, but you've actually got an object with a property called _embedded which contains an array called issues which is the array of issues that you're probably looking for. You should desrialize to an object, called Embedded, which contains a field called issues, which is an array of IssueDTO. Hope this helps. – Software Engineer Jan 05 '15 at 16:37
  • I already created 2 wrapper classes, one which has a single filed (IssueResponseWrapper) List issues and another wrapper class(EmbeddedWrapper) which has one field private IssueResponseWrapper _embedded; But i still can't get it working. – user2791841 Jan 05 '15 at 16:43
  • And if I change the attribute to private IssueDTO[] issues, I get the same error: org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: Unrecognized field "links" (class com.isdc.riskmanegement.imdatamanagement.dto.issue.Embedded), not marked as ignorable (one known property: "issues"]) at [Source: sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@4d3a956; line: 2, column: 14] (through reference chain: com.isdc.riskmanegement.imdatamanagement.dto.issue.Embedded["links"]); – user2791841 Jan 05 '15 at 16:58

0 Answers0