You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Prithvi Atal <pp...@gmail.com> on 2012/01/17 07:51:48 UTC
JSON data posted CXF rest service by Ajax is not getting decoded at
the java services
Hi All,
I am doing Post operation to the CXF rest services through jquery ajax as
below
url: url,
success: success,
type: "POST",
data:postData,
dataType: "json",
contentType: "application/json",
mimeType: "application/json",
async: true
postData has json data like below
employeeVO[0][userName]
employeeVO[1][firstName]
But the json data sent in encoded by the firefox browser and the java
services is throwing error json data expecting '{ ' instead of encoded data
%5...
error below
WARNWebApplicationExceptionMapper:58 - WebApplicationException has been
caught : org.codehaus.jettison.jso
n.JSONException: A JSONObject text must begin with '{' at character 1 of
employeeVO%5B0%5D%5BuserName%5D=6456454&employeeVO%5B1%
5D%5BfirstName%5D=6456
Any quick help please??? Thanks in Advance
--
View this message in context: http://cxf.547215.n5.nabble.com/JSON-data-posted-CXF-rest-service-by-Ajax-is-not-getting-decoded-at-the-java-services-tp5150845p5150845.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: JSON data posted CXF rest service by Ajax is not getting
decoded at the java services
Posted by Prithvi Atal <pp...@gmail.com>.
My problem got resolved.
@Sergey
>Can Jackson decode it ?
Jackson will not be decoding the value automatically.
>Should the JSON data come in the decoded form, given that it goes in the
message body ?
Yes that was the root cause of the problem. following solution worked:
in the ajax call instead of
data:postData,
changed to
data: JSON.stringify(postData),
And the problem got resolved,the json data was not getting encoded now.
I think ideally javascript object created in the json format needs to be
converted into Json String.
JSON.stringify(obj) — converts an JavaScript object to a JSON string
I referred this link http://www.sitepoint.com/javascript-json-serialization/
for Cross-browser JSON Serialization in JavaScript
it says
There are two JSON methods in JavaScript:
JSON.stringify(obj) — converts an JavaScript object to a JSON string
JSON.parse(str) — converts a JSON string back to a JavaScript object
Thx
--
View this message in context: http://cxf.547215.n5.nabble.com/JSON-data-posted-to-CXF-rest-service-by-Ajax-is-throwing-encoding-issue-by-the-java-services-tp5150845p5151594.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: JSON data posted CXF rest service by Ajax is not getting
decoded at the java services
Posted by Prithvi Atal <pp...@gmail.com>.
@Benson
Yes you' re right but the data to be posted was itself not in the json
format iinstead it was of type javascript object.
--
View this message in context: http://cxf.547215.n5.nabble.com/JSON-data-posted-to-CXF-rest-service-by-Ajax-is-throwing-encoding-issue-by-the-java-services-tp5150845p5151643.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: JSON data posted CXF rest service by Ajax is not getting decoded
at the java services
Posted by Benson Margulies <bi...@gmail.com>.
If content-type is application/json, it absolutely shouldn't look like that.
On Tue, Jan 17, 2012 at 6:53 AM, Sergey Beryozkin <sb...@gmail.com> wrote:
> Can Jackson decode it ?
>
> Should the JSON data come in the decoded form, given that it goes in the
> message body ?
>
> Cheers, Sergey
>
>
> On 17/01/12 06:51, Prithvi Atal wrote:
>>
>> Hi All,
>>
>> I am doing Post operation to the CXF rest services through jquery ajax as
>> below
>> url: url,
>> success: success,
>> type: "POST",
>> data:postData,
>> dataType: "json",
>> contentType: "application/json",
>> mimeType: "application/json",
>> async: true
>>
>> postData has json data like below
>>
>> employeeVO[0][userName]
>> employeeVO[1][firstName]
>>
>> But the json data sent in encoded by the firefox browser and the java
>> services is throwing error json data expecting '{ ' instead of encoded
>> data
>> %5...
>> error below
>> WARNWebApplicationExceptionMapper:58 - WebApplicationException has been
>> caught : org.codehaus.jettison.jso
>> n.JSONException: A JSONObject text must begin with '{' at character 1 of
>> employeeVO%5B0%5D%5BuserName%5D=6456454&employeeVO%5B1%
>> 5D%5BfirstName%5D=6456
>>
>> Any quick help please??? Thanks in Advance
>>
>> --
>> View this message in context:
>> http://cxf.547215.n5.nabble.com/JSON-data-posted-CXF-rest-service-by-Ajax-is-not-getting-decoded-at-the-java-services-tp5150845p5150845.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>
>
>
> --
> Sergey Beryozkin
>
> Talend Community Coders
> http://coders.talend.com/
>
> Blog: http://sberyozkin.blogspot.com
Re: JSON data posted CXF rest service by Ajax is not getting decoded
at the java services
Posted by Sergey Beryozkin <sb...@gmail.com>.
Can Jackson decode it ?
Should the JSON data come in the decoded form, given that it goes in the
message body ?
Cheers, Sergey
On 17/01/12 06:51, Prithvi Atal wrote:
> Hi All,
>
> I am doing Post operation to the CXF rest services through jquery ajax as
> below
> url: url,
> success: success,
> type: "POST",
> data:postData,
> dataType: "json",
> contentType: "application/json",
> mimeType: "application/json",
> async: true
>
> postData has json data like below
>
> employeeVO[0][userName]
> employeeVO[1][firstName]
>
> But the json data sent in encoded by the firefox browser and the java
> services is throwing error json data expecting '{ ' instead of encoded data
> %5...
> error below
> WARNWebApplicationExceptionMapper:58 - WebApplicationException has been
> caught : org.codehaus.jettison.jso
> n.JSONException: A JSONObject text must begin with '{' at character 1 of
> employeeVO%5B0%5D%5BuserName%5D=6456454&employeeVO%5B1%
> 5D%5BfirstName%5D=6456
>
> Any quick help please??? Thanks in Advance
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/JSON-data-posted-CXF-rest-service-by-Ajax-is-not-getting-decoded-at-the-java-services-tp5150845p5150845.html
> Sent from the cxf-user mailing list archive at Nabble.com.
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com