• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSON error serializing and transmitting data to Tomcat 6

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The following error is reported when trying to save a record to our MYSQL dba.

The error is reported in tomcat 6 logs:


3319:50907] -JSONValue failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=3 \"Unrecognised leading character\" UserInfo=0x7fb7c475d370 {NSLocalizedDescription=Unrecognised leading character}"

We are using JSON to serialize and transmit data to tomcat 6 web services

Platform:
Ubuntu 10.04
Java 64-bit
MYSQL 64-bit
Tomcat 6.0.33
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Damion!

Tomcat doesn't handle web services. If you want to handle web services using a Tomcat server you need to have a webapp that contains web services support within the webapp. The OS and database (if any) are irrelevant, as is the version of Tomcat.

Your error message indicatest that apparently an app is installed and using a JSON library from Stig Brautaset. Apparently you're not sending it data in the form it wants.

That's all we can tell from the little information available. We need a more complete stack trace/log and probably a copy of the actual JSON request data being sent or a reasonable facsimile.

 
Damion Daley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim,

Thanks for your response. A better fit Topic would have been to put " Tomcat error deserializing Json object"

This is the log from the failure.

Employee = <html><head><title>Apache Tomcat/6.0.33 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>com.google.gson.JsonParseException: The JsonDeserializer IntegerTypeAdapter failed to deserialized json object true given the type int
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:63)
com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationVisitor.visitChild(JsonDeserializationVisitor.java:107)
com.google.gson.JsonDeserializationVisitor.visitChildAsObject(JsonDeserializationVisitor.java:95)
com.google.gson.JsonObjectDeserializationVisitor.visitObjectField(JsonObjectDeserializationVisitor.java:61)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:164)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:548)
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:510)
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)
com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
com.google.gson.Gson.fromJson(Gson.java:568)
com.google.gson.Gson.fromJson(Gson.java:515)
com.google.gson.Gson.fromJson(Gson.java:484)
com.google.gson.Gson.fromJson(Gson.java:434)
com.google.gson.Gson.fromJson(Gson.java:406)
com.webapp.apis.EmployeeApi.updateEmployee(EmployeeApi.java:787)
com.webapp.apis.EmployeeApi.update(EmployeeApi.java:678)
com.jeeutils.APIFrontController.doPut(APIFrontController.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:640)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
</pre></p><p><b>root cause</b> <pre>java.lang.NumberFormatException: For input string: "true"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:449)
java.lang.Integer.parseInt(Integer.java:499)
com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:269)
com.google.gson.DefaultTypeAdapters$IntegerTypeAdapter.deserialize(DefaultTypeAdapters.java:719)
com.google.gson.DefaultTypeAdapters$IntegerTypeAdapter.deserialize(DefaultTypeAdapters.java:711)
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)
com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationVisitor.visitChild(JsonDeserializationVisitor.java:107)
com.google.gson.JsonDeserializationVisitor.visitChildAsObject(JsonDeserializationVisitor.java:95)
com.google.gson.JsonObjectDeserializationVisitor.visitObjectField(JsonObjectDeserializationVisitor.java:61)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:164)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:548)
com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter.deserialize(DefaultTypeAdapters.java:510)
com.google.gson.JsonDeserializerExceptionWrapper.deserialize(JsonDeserializerExceptionWrapper.java:50)
com.google.gson.JsonDeserializationVisitor.invokeCustomDeserializer(JsonDeserializationVisitor.java:88)
com.google.gson.JsonObjectDeserializationVisitor.visitFieldUsingCustomHandler(JsonObjectDeserializationVisitor.java:116)
com.google.gson.ObjectNavigator.navigateClassFields(ObjectNavigator.java:158)
com.google.gson.ObjectNavigator.accept(ObjectNavigator.java:131)
com.google.gson.JsonDeserializationContextDefault.fromJsonObject(JsonDeserializationContextDefault.java:73)
com.google.gson.JsonDeserializationContextDefault.deserialize(JsonDeserializationContextDefault.java:51)
com.google.gson.Gson.fromJson(Gson.java:568)
com.google.gson.Gson.fromJson(Gson.java:515)
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, it's running under Tomcat, but the error would have been the same under WebSphere, WebLogic, JBoss or whatever.

It looks like the fault lies here:

stack trace wrote:
com.google.gson.JsonParseException: The JsonDeserializer IntegerTypeAdapter failed to deserialized json object true given the type int



In other words, your JSON data includes a value of "true" where a number was expected and a NumberFormatConversion error was thrown attempting to make a number out of it.

It would have been nice if the error included some sort of hint as to WHICH of the data items had the lethal data type mismatch. Some parsers do, but I don't see anything here, so you'll have to figure it out the hard way, I guess.
 
Damion Daley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your reply. We just upgrade our IOS native app from 32-bit to 64-bit. We get these error when that app talks to our backend server (Webapp/Tomcat) and we try to save
a record to the MYSQL db.
My thoughts are that the Jason library is unable to read 64-bit int values. Does that sound like a possibility?

The other possibility is that the server is trying to insert 64-bit int in 32-bit column in db.

Any recommended first step to take on this?
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your error message quite explicitly says that it's trying to convert the literal text value "true" into an integer in the JSON processor. Nothing to do with how many bits, the database, or the OS. Just bad JSON data.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic