aspose file tools*
The moose likes Spring and the fly likes spring mvc xmlbean object JSON mapping error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "spring mvc xmlbean object JSON mapping error" Watch "spring mvc xmlbean object JSON mapping error" New topic
Author

spring mvc xmlbean object JSON mapping error

Md Iqbal
Greenhorn

Joined: Aug 26, 2011
Posts: 2
Restful service built using spring mvc framework. The requirement is to send response to the client either in XML or JSON format depending upon the Accept HTTP header attribute value.

Works well when the response is in XML. Fails for JSON string.

Stack trace:
=============================================================
org.codehaus.jackson.map.JsonMappingException: Could not get a Java numeric typ
from a Schema complex type (through reference chain: com.dell.it.services.sdr.
esponse.dataservice.impl.DataServiceResponseDocumentImpl["dataServiceResponse"]
>com.dell.it.services.sdr.response.dataservice.impl.DataServiceResponseImpl["ap
plicationData"]->com.dell.it.services.sdr.response.dataservice.impl.Appplicatio
DataImpl["floatValue"])
at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappi
gException.java:218)
at org.codehaus.jackson.map.JsonMappingException.wrapWithPath(JsonMappi
gException.java:183)
at org.codehaus.jackson.map.ser.SerializerBase.wrapAndThrow(SerializerB
se.java:131)
at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSeri
lizer.java:183)
at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer
java:142)
Truncated. see log file for complete stacktrace

Caused By: org.apache.xmlbeans.impl.values.XmlValueNotSupportedException: Could
not get a Java numeric type from a Schema complex type
at org.apache.xmlbeans.impl.values.XmlObjectBase.getBigDecimalValue(XmlO
bjectBase.java:1395)
at org.apache.xmlbeans.impl.values.XmlObjectBase.getFloatValue(XmlObject
Base.java:1391)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
Truncated. see log file for complete stacktrace
>
======================================================

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

What does your code with annotations look like in your Controller. Do you have the Jackson jars in your classpath. Does the domain object being returned have a circular reference to another domain object. I am assuming your domain objects are annotated with xml annotations for the xml part, and assume that there aren't any annotations for the JSON part. Which is ok, but it you have a circular reference then Jackson will not be able to create the JSON because it won't know how far to go and keep going round and round and round.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Md Iqbal
Greenhorn

Joined: Aug 26, 2011
Posts: 2
The requirement is to send the response both in xml or json format depending upon the HTTP header "Accept" attribute. It works well when the client consuming the application request with Accept=application/xml but fails when Accept=application/json.

Controller File:
----------------


The jackson jar used is jackson-all-1.8.5.jar. I also have the json-lib-2.1-jdk13.jar file as well in the classpath.

I even tried with a simple xsd with request and response conforming to these xsd. Throws the same exception. I have tried replacing xmlbean by jaxb api's in different project. The conversion to jaxb object to json works well then. But my project requirement is to use xmlbean.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Make sure you post here with the CODE tag when posting code so we can read it.

So based on the code you are using Spring 3.x, so why aren't you using Spring REST to handle this? You shouldn't return ModelAndView. It is much easier than that.




So the idea is that you shouldn't have any parsing to create xml or json in your Controller code, or really in any code anywhere in your application, because then you are too tightly coupled to that code and other api/technologies and you have lowered your cohesion in the Controller method and now it is doing more than one thing.

Hope that helps. The only code I can't show or give to you is how you create a DataServiceRequestDocument domain object. It should be a POJO with properties and getters and setters. Like as an example



Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: spring mvc xmlbean object JSON mapping error