Jquery Json parser showing invalid character error for jersey rest webservice response -
i'm creating json rest webservice mediatype property
@get @produces(mediatype.application_json) public issues getallopenpoints() {
i'm using jackson jars creating json response. not creating json manually still when trying parse response jquery. throws invalid characher error.
$.parsejson(result);
do need encode or escape data in objects before returning rest webservice. whats point of using auto response conversion jackson.
i believe know problem in json parsing still looking reason. problem due structure of object graph have.
- first designed xml manually.
- then generated schema xml
- then used eclipse create java objects xsd.
below xml started with..
<issues> <issue> <product>xxxx</product> <datereported>xxxx</datereported> <summary>xxxx</summary> <status>xxxx</status> <responsibleperson>xxxx </responsibleperson> <targetcompletiondate>xxxx</targetcompletiondate> <completiondate>xxx</completiondate> <application>xxxx</application> <priority>xxxx</priority> <comments> <comment> <date>xxxxx</date> <description>xxxxx</description> </comment> <comment> <date>xxxxx</date> <description>xxxxx</description> </comment> </comments> </issue> ...... ...... </issues>
issue class contains object of type comments , comments object contains list of object type comment. if had started creating java object first instead of xml, have kept list of "comment" in issue class rather 1 comments object.
now resulting in following json.
{ "issue": [ { "product": "xxxxx", "datereported": "xxxxx", "summary": "xxxxx", "status": "xxxxx", "responsibleperson": "xxxxx", "targetcompletiondate": "xxxxx", "completiondate": "xxxxx", "application": "xxxxx", "priority": 1, "comments":{ "comment":[ { "date": "xxxxx", "description": "xxxxx" }, { "date": "xxxxx", "description": "xxxxx" } ] } } ] }
if edit json , try parse following json in sample js file. works fine.
{ "issue": [ { "product": "xxxxx", "datereported": "xxxxx", "summary": "xxxxx", "statu??s": "xxxxx", "responsibleperson": "xxxxx", "targetcompletiondate": "xxxxx", "??completiondate": "xxxxx", "application": "xxxxx", "priority": 1, "comments": [ { "date": "xxxxx", "description": "xxxxx" }, { "date": "xxxxx", "de??scription": "xxxxx" } ] } ] }
but first json valid object representation. why exception thrown in parsing ?
Comments
Post a Comment