You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jaco Prinsloo <ja...@gmail.com> on 2010/11/15 09:05:39 UTC
Excluding empty array elements from the generated message
Hi,
I have an element which is annotated as given below:
@XmlElement(name = "Items", nillable = false, required = false)
public String[] getItems() {
return items;
}
It generates fine when it contains items, and generates an empty element
when it does not:
<ns2:Items />
Is there any way that I can configure Apache CXF to exclude this element
when it is empty, in other words, not to generate anything for it?
Thank you,
Jaco
Re: Excluding empty array elements from the generated message
Posted by Jaco Prinsloo <ja...@gmail.com>.
Hi Freeman,
Thanks for the reply.
Setting nillable=true and the items to null results in the following entry:
<ns2:Items xmlns:ns3="http://www.w3.org/2001/XMLSchema-instance"
ns3:nil="true"/>
Setting nillable=false and the items to null results in my desired
behaviour.
Thank a lot!
Jaco
On Mon, Nov 15, 2010 at 12:05 PM, Freeman Fang <fr...@gmail.com>wrote:
> Hi Jaco,
>
> I believe if you use nillable=true and setItems(null), there should be no
> <ns2:Items />.
> But if you setItems(new String[]) string[] isn't null but the length is 0,
> I think have <ns2:Items /> is expected behavior, as it's different with
> null.
>
> Freeman
>
>
> On 2010-11-15, at 下午5:00, Jaco Prinsloo wrote:
>
> Hi Freeman,
>>
>> Sorry, I should have added. I tried setting nillable to false and I also
>> tried leaving it out completely, but none of it helped.
>>
>> Thank you,
>> Jaco
>>
>> On Mon, Nov 15, 2010 at 10:11 AM, Freeman Fang <freeman.fang@gmail.com
>> >wrote:
>>
>>
>>> On 2010-11-15, at 下午4:05, Jaco Prinsloo wrote:
>>>
>>> Hi,
>>>
>>>>
>>>> I have an element which is annotated as given below:
>>>>
>>>> @XmlElement(name = "Items", nillable = false, required = false)
>>>> public String[] getItems() {
>>>> return items;
>>>> }
>>>>
>>>> Hi,
>>>
>>> How about change nillable=true to see if it helps?
>>>
>>> Freeman
>>>
>>>
>>> It generates fine when it contains items, and generates an empty element
>>>> when it does not:
>>>>
>>>> <ns2:Items />
>>>>
>>>> Is there any way that I can configure Apache CXF to exclude this element
>>>> when it is empty, in other words, not to generate anything for it?
>>>>
>>>> Thank you,
>>>> Jaco
>>>>
>>>>
>>>
>>> --
>>> Freeman Fang
>>>
>>> ------------------------
>>>
>>> FuseSource: http://fusesource.com
>>> blog: http://freemanfang.blogspot.com
>>> twitter: http://twitter.com/freemanfang
>>> Apache Servicemix:http://servicemix.apache.org
>>> Apache Cxf: http://cxf.apache.org
>>> Apache Karaf: http://karaf.apache.org
>>> Apache Felix: http://felix.apache.org
>>>
>>>
>>>
>
> --
> Freeman Fang
>
> ------------------------
>
> FuseSource: http://fusesource.com
> blog: http://freemanfang.blogspot.com
> twitter: http://twitter.com/freemanfang
> Apache Servicemix:http://servicemix.apache.org
> Apache Cxf: http://cxf.apache.org
> Apache Karaf: http://karaf.apache.org
> Apache Felix: http://felix.apache.org
>
>
Re: Excluding empty array elements from the generated message
Posted by Freeman Fang <fr...@gmail.com>.
Hi Jaco,
I believe if you use nillable=true and setItems(null), there should be
no <ns2:Items />.
But if you setItems(new String[]) string[] isn't null but the length
is 0, I think have <ns2:Items /> is expected behavior, as it's
different with null.
Freeman
On 2010-11-15, at 下午5:00, Jaco Prinsloo wrote:
> Hi Freeman,
>
> Sorry, I should have added. I tried setting nillable to false and I
> also
> tried leaving it out completely, but none of it helped.
>
> Thank you,
> Jaco
>
> On Mon, Nov 15, 2010 at 10:11 AM, Freeman Fang
> <fr...@gmail.com>wrote:
>
>>
>> On 2010-11-15, at 下午4:05, Jaco Prinsloo wrote:
>>
>> Hi,
>>>
>>> I have an element which is annotated as given below:
>>>
>>> @XmlElement(name = "Items", nillable = false, required = false)
>>> public String[] getItems() {
>>> return items;
>>> }
>>>
>> Hi,
>>
>> How about change nillable=true to see if it helps?
>>
>> Freeman
>>
>>
>>> It generates fine when it contains items, and generates an empty
>>> element
>>> when it does not:
>>>
>>> <ns2:Items />
>>>
>>> Is there any way that I can configure Apache CXF to exclude this
>>> element
>>> when it is empty, in other words, not to generate anything for it?
>>>
>>> Thank you,
>>> Jaco
>>>
>>
>>
>> --
>> Freeman Fang
>>
>> ------------------------
>>
>> FuseSource: http://fusesource.com
>> blog: http://freemanfang.blogspot.com
>> twitter: http://twitter.com/freemanfang
>> Apache Servicemix:http://servicemix.apache.org
>> Apache Cxf: http://cxf.apache.org
>> Apache Karaf: http://karaf.apache.org
>> Apache Felix: http://felix.apache.org
>>
>>
--
Freeman Fang
------------------------
FuseSource: http://fusesource.com
blog: http://freemanfang.blogspot.com
twitter: http://twitter.com/freemanfang
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org
Re: Excluding empty array elements from the generated message
Posted by Jaco Prinsloo <ja...@gmail.com>.
Hi Freeman,
Sorry, I should have added. I tried setting nillable to false and I also
tried leaving it out completely, but none of it helped.
Thank you,
Jaco
On Mon, Nov 15, 2010 at 10:11 AM, Freeman Fang <fr...@gmail.com>wrote:
>
> On 2010-11-15, at 下午4:05, Jaco Prinsloo wrote:
>
> Hi,
>>
>> I have an element which is annotated as given below:
>>
>> @XmlElement(name = "Items", nillable = false, required = false)
>> public String[] getItems() {
>> return items;
>> }
>>
> Hi,
>
> How about change nillable=true to see if it helps?
>
> Freeman
>
>
>> It generates fine when it contains items, and generates an empty element
>> when it does not:
>>
>> <ns2:Items />
>>
>> Is there any way that I can configure Apache CXF to exclude this element
>> when it is empty, in other words, not to generate anything for it?
>>
>> Thank you,
>> Jaco
>>
>
>
> --
> Freeman Fang
>
> ------------------------
>
> FuseSource: http://fusesource.com
> blog: http://freemanfang.blogspot.com
> twitter: http://twitter.com/freemanfang
> Apache Servicemix:http://servicemix.apache.org
> Apache Cxf: http://cxf.apache.org
> Apache Karaf: http://karaf.apache.org
> Apache Felix: http://felix.apache.org
>
>
Re: Excluding empty array elements from the generated message
Posted by Freeman Fang <fr...@gmail.com>.
On 2010-11-15, at 下午4:05, Jaco Prinsloo wrote:
> Hi,
>
> I have an element which is annotated as given below:
>
> @XmlElement(name = "Items", nillable = false, required = false)
> public String[] getItems() {
> return items;
> }
Hi,
How about change nillable=true to see if it helps?
Freeman
>
> It generates fine when it contains items, and generates an empty
> element
> when it does not:
>
> <ns2:Items />
>
> Is there any way that I can configure Apache CXF to exclude this
> element
> when it is empty, in other words, not to generate anything for it?
>
> Thank you,
> Jaco
--
Freeman Fang
------------------------
FuseSource: http://fusesource.com
blog: http://freemanfang.blogspot.com
twitter: http://twitter.com/freemanfang
Apache Servicemix:http://servicemix.apache.org
Apache Cxf: http://cxf.apache.org
Apache Karaf: http://karaf.apache.org
Apache Felix: http://felix.apache.org