• 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

spring mvc xmlbean object JSON mapping error

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
>
======================================================

 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Md Iqbal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic