Tuesday, 10 September 2013

Force nil elements in marshalled XML

Force nil elements in marshalled XML

I have a system which calls a web service, and passes the response back to
its own caller (mostly untouched). The problem is that in the response
which my system receives, several elements are marked as xsi:nil="true",
but in the response my system sends to its caller, those elements are
absent!
In my system, the schema which defines these elements defines them like this:
<xsd:element name="trmCode" type="xsd:string" nillable="true" minOccurs="1"/>
The Java code that is generated from the schema defines a class member
like this:
@XmlElement(required = true, nillable = true)
protected String trmCode;
The data I receive from the web service contains the element like this:
<trmCode xsi:nil="true" />
The first time I call my system's service, the element is returned like this:
<trmCode />
All subsequent calls don't include trmCode in the response at all. The
code that transfers data from the called web service's response to my
system's response is very simple:
outboundResponse.setListOfThings(inboundResponse.getListOfThings());
Where each "thing" in ListOfThings is an object with a trmCode member
(among others, all of which exhibit the same problem if they are null on
the inbound response).
Has anyone ever seen anything like this before? Does anyone have any ideas
how to ensure that my output will contain <trmCode xsi:nil="true"/>?

No comments:

Post a Comment