Hi, I have also come across this problem of CXF not marshalling the empty tags. For example if there no middle name for the customer, I am thinking of having an empty element to show up in the response rather than missing the whole element itself. I have modified my XSD to with nillable="true" attribute, then my REST service has generated the following response XML putting xsi:nil="true" while I am expecting just <middleName/>. My JSON end point with the same service has totally failed with the following exception. Please advice to address this issue.
Thanks, Durga Response XML: <ns2:customerStatus xmlns:ns2="http://mydomain.com/types"> <id>602569</id> <firstName>test</firstName> <middleName xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" /> <lastName>last</lastName> <address1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" /> <status>Active</status> </ns2:customerStatus> Exception stack for JSON Service: Caused by: java.lang.IllegalStateException: Invalid JSON namespace: http://www.w3.org/2001/XMLSchema-instance at org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(MappedNamespaceConvention.java:148) at org.codehaus.jettison.mapped.MappedNamespaceConvention.createAttributeKey(MappedNamespaceConvention.java:136) at org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:89) at com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLStreamWriterOutput.java:90) at com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:402) at com.sun.xml.bind.v2.runtime.XMLSerializer.writeXsiNilTrue(XMLSerializer.java:719) at com.sun.xml.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:66) at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:286) at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:619) dkulp wrote: > > > On Wednesday 03 October 2007, Benson Margulies wrote: >> Is this the 'nillable' / 'minOccurs' issue? > > This is slightly different but comes down to the same solution. That > issue is basically that we treat an empty list exactly the same on the > wire as a null list. With the normal jaxb mapping, there isn't a way > to say weather the list was null or empty. Either way ends up with no > data at all written out on the wire. You end up having to create a > wrapper type that is then nillable. > > Dan > >> >> > -----Original Message----- >> > From: Daniel Kulp [mailto:[EMAIL PROTECTED] >> > Sent: Wednesday, October 03, 2007 7:47 AM >> > To: [email protected] >> > Cc: Kaleb Walton >> > Subject: Re: Empty List's not being marshaled? >> > >> > On Wednesday 03 October 2007, Kaleb Walton wrote: >> > > Do you know why that is the case? Maybe because since it's empty >> >> they >> >> > > figured there shouldn't be any wasted space in the XML doc? >> > >> > It's probably a combination of: >> > 1) Less bandwidth used on the wire >> > >> > 2) Mappings in other toolkits - toolkits like JAXB and .NET and >> >> JAX-RPC, >> >> > etc.... usually map the "wrapper" type to an object that holds the >> >> list >> >> > or array, but would map the current thing directly to an array or >> >> list. >> >> > That simplifies the programming model. >> > >> > 2) Simplified schema. You don't end up with a wrapper type for >> > every list. Imaging, for example, a method that takes 3 lists. >> > With wrapped/doc/lit, you currently end up with something like: >> > <element name="doFooRequest"> >> > <complexType> >> > <sequence> >> > <element name="foo" type="string" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > <element name="bar" type="long" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > <element name="snarf" type="float" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > </sequence> >> > <complexType> >> > </element> >> > >> > If you had to wrap all the lists up, it would be something like: >> > <complexType name="StringList"> >> > <sequence> >> > <element name="item" type="string" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > </sequence> >> > <complexType> >> > <complexType name="IntList"> >> > <sequence> >> > <element name="item" type="int" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > </sequence> >> > <complexType> >> > <complexType name="FloatList"> >> > <sequence> >> > <element name="item" type="float" >> > minOccurs="0" maxOccurs="unbounded" nillable="true"/> >> > </sequence> >> > <complexType> >> > <element name="doFooRequest"> >> > <complexType> >> > <sequence> >> > <element name="foo" type="tns:StringList"/> >> > <element name="bar" type="tns:IntList"/> >> > <element name="snarf" type="tns:FloatList"/> >> > </sequence> >> > <complexType> >> > </element> >> > >> > Basically, you end up with a significantly larger schema. >> > >> > Dan >> > >> > > It's a pain for my consumers to have to check for the existence of >> > > a variable before trying to parse it out - not the end of the >> > > world >> >> but >> >> > > it adds somewhat redundant code. >> > > >> > > >> > > Regards, >> > > Kaleb >> > > >> > > |------------> >> > > | From: | >> > > |------------> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > > >> > > |Daniel Kulp <[EMAIL PROTECTED]> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > | >> > > |------------> >> > > | To: | >> > > |------------> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > > >> > > |[email protected] >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > | >> > > |------------> >> > > | Cc: | >> > > |------------> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > > >> > > |Kaleb Walton/Southfield/[EMAIL PROTECTED] >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > | >> > > |------------> >> > > | Date: | >> > > |------------> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > > >> > > |10/02/2007 05:55 PM >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > | >> > > |------------> >> > > | Subject: | >> > > |------------> >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > > >> > > |Re: Empty List's not being marshaled? >> > >> >------------------------------------------------------------------- >> > >> >------------------------------------------------------------------- >> > >> > > >------------| >> > > >> > > On Tuesday 02 October 2007, Kaleb Walton wrote: >> > > > I'm using the simple server configured via Spring. When an >> > > > object contains an empty list (not null) my response does not >> > > > return it >> >> as >> >> > > > an empty list - it just excludes the property from the response. >> >> Is >> >> > > > there any way to force it to include the property? >> > > >> > > I'd probably have to see both the schema and the soap message. >> >> Most >> >> > > likely, the answer is no without creating a holder bean to hold >> > > the list. >> > > >> > > For the most part, when we see something like List<String>, we >> > > just create: >> > > <element name="foo" type="string" maxOccurs="unbounded" >> > > nillable="true"/> >> > > >> > > In that case, if the list is empty (or even if the list is null), >> > > nothing representing the list will appear on the wire. That is >> > > how the JAXB spec calls for it to be done. If you want something >> > > always on the wire, the schema would have to be something like: >> > > <element name="fooList"> >> > > <complexType> >> > > <sequence> >> > > <element name="foo" type="string" maxOccurs="unbounded" >> > > nillable="true"/> </sequence> >> > > <complexType> >> > > </element> >> > > >> > > and a "FooList" class would be created to hold the List<String>. >> > > >> > > -- >> > > J. Daniel Kulp >> > > Principal Engineer >> > > IONA >> > > P: 781-902-8727 C: 508-380-7194 >> > > [EMAIL PROTECTED] >> > > http://www.dankulp.com/blog >> > >> > -- >> > J. Daniel Kulp >> > Principal Engineer >> > IONA >> > P: 781-902-8727 C: 508-380-7194 >> > [EMAIL PROTECTED] >> > http://www.dankulp.com/blog > > > > -- > J. Daniel Kulp > Principal Engineer > IONA > P: 781-902-8727 C: 508-380-7194 > [EMAIL PROTECTED] > http://www.dankulp.com/blog > > -- View this message in context: http://www.nabble.com/Empty-List%27s-not-being-marshaled--tf4557811.html#a13031644 Sent from the cxf-user mailing list archive at Nabble.com.
