JsonParseException on Valid JSON
Posted
by
user2909602
on Stack Overflow
See other posts from Stack Overflow
or by user2909602
Published on 2013-10-23T03:49:26Z
Indexed on
2013/10/23
3:53 UTC
Read the original article
Hit count: 437
I am having an issue calling a RESTful service from my client code. I have written the RESTful service using CXF/Jackson, deployed to localhost, and tested using RESTClient successfully. Below is a snippet of the service code:
@POST
@Produces("application/json")
@Consumes("application/json")
@Path("/set/mood")
public Response setMood(MoodMeter mm) {
this.getMmDAO().insert(mm);
return Response.ok().entity(mm).build();
}
The model class and dao work successfully and the service itself works fine using RESTClient. However, when I attempt to call this service from Java Script, I get the error below on the server side:
Caused by: org.codehaus.jackson.JsonParseException: Unexpected character ('m' (code 109)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
I have copied the client side code below. To make sure it has nothing to do with the JSON data itself, I used a valid JSON string (which works using RESTClient, JSON.parse() method, and JSONLint) in the vars 'json' (string) and 'jsonData' (JSON). Below is the Java Script code:
var json = '{"mood_value":8,"mood_comments":"new comments","user_id":5,"point":{"latitude":37.292929,"longitude":38.0323323},"created_dtm":1381546869260}';
var jsonData = JSON.parse(json);
$.ajax({
url: 'http://localhost:8080/moodmeter/app/service/set/mood',
dataType: 'json',
data: jsonData,
type: "POST",
contentType: "application/json"
});
I've seen the JsonParseException a number of times on other threads, but in this case the JSON itself appears to be valid (and tested). Any thoughts are appreciated.
© Stack Overflow or respective owner