eclipse-ee4j / jersey

Eclipse Jersey Project - Read our Wiki:
https://github.com/eclipse-ee4j/jersey/wiki
Other
680 stars 339 forks source link

Unmarshalling error when parsing a JSON message generated from Jira 5.1.x #1731

Closed jerseyrobot closed 11 years ago

jerseyrobot commented 11 years ago

Hi,

I'm trying to unmarshall a REST response I get from a Jira instance v5.1.6. REST format is always JSON from this version of JIRA.

The error I get is a

java.lang.IllegalArgumentException: No more parsing elements.
    at com.sun.jersey.json.impl.reader.JsonXmlStreamReader.next(JsonXmlStreamReader.java:503) ~[jersey-json-1.14.jar:1.14]
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:197) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:366) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:345) ~[jaxb-impl-2.2.3-1.jar:2.2.3]
    at com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalJAXBElementFromJSON(BaseJSONUnmarshaller.java:111) ~[jersey-json-1.14.jar:1.14]
    at com.sun.jersey.json.impl.BaseJSONUnmarshaller.unmarshalFromJSON(BaseJSONUnmarshaller.java:100) ~[jersey-json-1.14.jar:1.14]
    at com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider.readFrom(JSONRootElementProvider.java:129) ~[jersey-json-1.14.jar:1.14]
    at com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.readFrom(AbstractRootElementProvider.java:111) ~[jersey-core-1.14.jar:1.14]
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:565) ~[jersey-client-1.14.jar:1.14]
    at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:517) ~[jersey-client-1.14.jar:1.14]
    at com.sun.jersey.api.client.WebResource.handle(WebResource.java:684) ~[jersey-client-1.14.jar:1.14]
    at com.sun.jersey.api.client.WebResource.get(WebResource.java:191) ~[jersey-client-1.14.jar:1.14]

JSONConfig uses the natural notation.

I ran the code in debug mode and saw that in the method StAXStreamConnector.bridge(), in the while loop, there is no check concerning event XMLStreamConstants.END_DOCUMENT and the exception is raised exactly after the last element of the JSON response, at a point where the inputstream is at its end and the depth level is still at 1 (what I couldn't explain).

The while loop expects the depth level to be 0 for a perfectly parsed input.

Could you take a look and help me on this ?

The JSON response is as follows

{
   "expand":"names,schema",
   "startAt":0,
   "maxResults":1,
   "total":4965,
   "issues":[
      {
         "expand":"editmeta,renderedFields,transitions,changelog,operations",
         "id":"325150",
         "self":"https://example.com/jira/rest/api/latest/issue/325150",
         "key":"CITNET-5673",
         "fields":{
            "summary":"Problem trying to attach Screenshot to JIRA issue",
            "progress":{
               "progress":0,
               "total":0
            },
            "issuetype":{
               "self":"https://example.com/jira/rest/api/2/issuetype/5",
               "id":"5",
               "description":"Support request on a product",
               "iconUrl":"https://example.com/jira/images/icons/help.png",
               "name":"Support",
               "subtask":false
            },
            "timespent":null,
            "reporter":{
               "self":"https://example.com/jira/rest/api/2/user?username=neessisd",
               "name":"neessisd",
               "emailAddress":"EMPL-EESSI-SERVICE-DESK@ec.europa.eu",
               "avatarUrls":{
  "16x16":"https://example.com/jira/secure/useravatar?size=small&ownerId=neessisd&avatarId=10163",
  "48x48":"https://example.com/jira/secure/useravatar?ownerId=neessisd&avatarId=10163"
               },
               "displayName":"EESSI SD",
               "active":true
            },
            "customfield_10490":null,
            "created":"2012-10-10T12:00:11.000+0200",
            "updated":"2012-10-10T12:05:09.000+0200",
            "description":"Java error when trying to attach a Screenshot in JIRA.",
            "priority":{
               "self":"https://example.com/jira/rest/api/2/priority/3",
               "iconUrl":"https://example.com/jira/images/icons/priority_major.gif",
               "name":"Major",
               "id":"3"
            },
            "issuelinks":[

            ],
            "customfield_12633":null,
            "customfield_12632":null,
            "customfield_12631":null,
            "customfield_12630":"98733",
            "subtasks":[

            ],
            "status":{
               "self":"https://example.com/jira/rest/api/2/status/1",
               "description":"The issue is open and ready for the assignee to start work on it.",
               "iconUrl":"https://example.com/jira/images/icons/status_open.gif",
               "name":"Open",
               "id":"1"
            },
            "labels":[

            ],
            "workratio":-1,
            "customfield_10250":null,
            "project":{
               "self":"https://example.com/jira/rest/api/2/project/CITNET",
               "id":"10020",
               "key":"CITNET",
               "name":"_CITnet",
               "avatarUrls":{
  "16x16":"https://example.com/jira/secure/projectavatar?size=small&pid=10020&avatarId=10254",
  "48x48":"https://example.com/jira/secure/projectavatar?pid=10020&avatarId=10254"
               }
            },
            "environment":null,
            "aggregateprogress":{
               "progress":0,
               "total":0
            },
            "components":[
               {
  "self":"https://example.com/jira/rest/api/2/component/12599",
  "id":"12599",
  "name":"Jira",
  "description":"CITnet issues tracker (JIRA)"
               }
            ],
            "customfield_10010":null,
            "timeoriginalestimate":null,
            "customfield_10360":{
               "self":"https://example.com/jira/rest/api/2/customFieldOption/10452",
               "value":"No",
               "id":"10452"
            },
            "customfield_10580":null,
            "votes":{
               "self":"https://example.com/jira/rest/api/2/issue/CITNET-5673/votes",
               "votes":0,
               "hasVoted":false
            },
            "fixVersions":[

            ],
            "resolution":null,
            "resolutiondate":null,
            "aggregatetimeoriginalestimate":null,
            "customfield_12634":null,
            "duedate":null,
            "customfield_12730":"Not Started",
            "customfield_12635":null,
            "customfield_12636":null,
            "customfield_12637":null,
            "customfield_12731":null,
            "customfield_12638":null,
            "customfield_12639":null,
            "watches":{
               "self":"https://example.com/jira/rest/api/2/issue/CITNET-5673/watchers",
               "watchCount":1,
               "isWatching":false
            },
            "customfield_10600":[
               "neessisd:2"
            ],
            "assignee":null,
            "customfield_10590":null,
            "customfield_11730":null,
            "aggregatetimeestimate":null,
            "versions":[

            ],
            "timeestimate":null,
            "aggregatetimespent":null
         }
      }
   ]
}

Thx, – Issa

Environment

java version "1.7.0_05" Java(TM) SE Runtime Environment (build 1.7.0_05-b06) Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)

activation-1.1.jar bcprov-jdk16-1.46.jar commons-codec-1.6.jar commons-collections-3.2.1.jar commons-configuration-1.9.jar commons-configuration-1.9-javadoc.jar commons-configuration-1.9-sources.jar commons-digester-1.8.1.jar commons-httpclient-3.1.jar commons-lang-2.6.jar commons-lang3-3.1.jar commons-lang3-3.1-javadoc.jar commons-lang3-3.1-sources.jar jackson-core-asl-1.9.2.jar jackson-jaxrs-1.9.2.jar jackson-mapper-asl-1.9.2.jar jackson-xc-1.9.2.jar jaxb-api-2.2.2.jar jaxb-impl-2.2.3-1.jar jcl-over-slf4j-1.7.1.jar jcl-over-slf4j-1.7.1-javadoc.jar jcl-over-slf4j-1.7.1-sources.jar jersey-apache-client-1.14.jar jersey-apache-client-1.14-javadoc.jar jersey-apache-client-1.14-sources.jar jersey-client-1.14.jar jersey-client-1.14-javadoc.jar jersey-client-1.14-sources.jar jersey-core-1.14.jar jersey-core-1.14-javadoc.jar jersey-core-1.14-sources.jar jersey-json-1.14.jar jersey-json-1.14-javadoc.jar jersey-json-1.14-sources.jar jettison-1.1.jar jsr311-api-1.1.1.jar jzlib-1.0.7.jar logback-classic-1.0.7.jar logback-classic-1.0.7-javadoc.jar logback-classic-1.0.7-sources.jar logback-core-1.0.7.jar mail-1.4.jar slf4j-api-1.7.1.jar sshj-0.8.1.jar sshj-0.8.1-javadoc.jar sshj-0.8.1-sources.jar stax-api-1.0.1.jar stax-api-1.0-2.jar xml-apis-1.0.b2.jar

Affected Versions

[1.14]

jerseyrobot commented 6 years ago
jerseyrobot commented 11 years ago

@glassfishrobot Commented Reported by flopma

jerseyrobot commented 11 years ago

@glassfishrobot Commented flopma said: Oopps, please change the issue description formatting as it is rendered very badly now! Thx!

jerseyrobot commented 11 years ago

@glassfishrobot Commented jesseplymale said: I'm using Jersey version 1.14. I noticed this problem too. It happened when I first was unmarshalling a Java bean to JSON using the POJO method (which included nulls). Then I turned off the JSONConfiguration.FEATURE_POJO_MAPPING, so that it was only using the JSONConfiguration.natural() method. I tried calling a web service with the earlier JSON that I had saved off, and it gave me the "No more parsing elements." error above. I was able to avoid the problem by removing the elements from the JSON which had null values. I'm curious what a better fix would be.

jerseyrobot commented 11 years ago

@glassfishrobot Commented michalgajdos said: Merged into trunk (1.16-SNAPSHOT).

jerseyrobot commented 11 years ago

@glassfishrobot Commented Was assigned to michalgajdos

jerseyrobot commented 7 years ago

@glassfishrobot Commented This issue was imported from java.net JIRA JERSEY-1459

jerseyrobot commented 11 years ago

@glassfishrobot Commented Marked as fixed on Friday, November 23rd 2012, 3:23:24 am