Can't unmarshall REST response Spring-Jibx

228 views Asked by At

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

0

There are 0 answers