0

I have a problem unmarshalling a RESTful request body using Spring and Jibx.

This is the request body I'm sending through Postman:

<?xml version="1.0" encoding="utf-8"?>
<locationRequest xmlns="urn:ietf:params:xml:ns:geopriv:held" responseTime="30000">
  <locationType exact="true">
    geodetic
    civic 
    locationURI
  </locationType>
  <device xmlns="urn:ietf:params:xml:ns:geopriv:held:id">
    <uri>tel:123456789;phone-context=+1</uri>
  </device>
</locationRequest>  

This is my binding.xml

...
<mapping name="locationRequest" class="com.example.integrations.models.LocationRequest" ordered="true">
    <namespace uri="urn:ietf:params:xml:ns:geopriv:held" default="elements" />
    <value name="responseTime" field="responseTime" style="attribute" usage="optional"/>
    <structure name="locationType" field="locationType" map-as="locationType" usage="required"/>
    <structure field="device" usage="required"/>
</mapping>


<mapping name="device" class="com.example.integrations.models.Device" >
    <namespace uri="urn:ietf:params:xml:ns:geopriv:held:id" default="elements" />
    <value name="uri" field="uri" />
</mapping>

<mapping abstract="true" type-name="locationType" class="com.example.integrations.models.LocationType">
    <value name="exact" field="exact" style="attribute"/>
    <value field="types" style="text"
           serializer="com.example.integrations.ParseUtil.serializeStringList"
           deserializer="com.example.integrations.ParseUtil.deserializeStringList" />
</mapping>
...

When I run the Jibx compiler everything is fine and all classes are detected and modified by the compiler correctly

This is the method that receive the web service call:

current_code

The request its unmarshalled correctly if I use a .xml file as the input, but if I go through the web service its missing some data:

...
 <locationType exact="true">
    geodetic
    civic 
    locationURI
  </locationType>
...

The "exact" attribute is parsed correctly, but the content, while on the xml file was parsed ok, is missing in the web service object... and for the love of me I can't figure out why.

(Note: Also the response object (LocationResponse) is not marshalled correctly when returning to Postman)

This is my Spring-servlet configuration relevant to jibx:

...
    <beans:bean id="unmarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
        <beans:property name="targetClass" value="org.dellroad.jibxbindings.pidf.held.LocationRequest"/>
        <beans:property name="bindingName" value="locationRequest"/>
    </beans:bean>

    <beans:bean id="marshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
        <beans:property name="targetClass" value="org.dellroad.jibxbindings.pidf.held.LocationRequest"/>
        <beans:property name="bindingName" value="locationRequest"/>
    </beans:bean>
...

What am I missing here? I suspect is a missconfiguration in the Spring side

  • Did you capture the response and checked if its well formed? – Amit Mahajan Jan 08 '17 at 06:29
  • While my concern is focused on the request unmarshalling, the response have indeed all is elements but its not adjusted to the jibx rules defined (not posted, because they are quite long and complex)... I pointed that out (the response) because it may be a hint to whats wrong (maybe jibx not doing its job properly?) it feels like a default xml parser is running and everything is being parsed like a normal xml would – Ivan Alburquerque Jan 08 '17 at 06:36
  • Perhaps this might help http://stackoverflow.com/questions/4168652/jibx-how-to-unmarshal-marshal-tag-with-value-and-attribute – Amit Mahajan Jan 08 '17 at 06:53
  • I have the same setup on locationType element, works if I input the file xml, but not on web service parameter, so I know at least the binding works correctly as is. the link didnt provide anything helpful :( – Ivan Alburquerque Jan 08 '17 at 18:16

0 Answers0