Re: [castor-dev] Force an element to be marshalled
August Detlefsen <[email protected]> Thu, 15 Oct 2009 13:05:32 -0700 (PDT)
| Newsgroups | gmane.comp.java.castor.devel |
|---|---|
| Message-ID | <[email protected]> |
I don't think the legacy system at the other end can handle elements like that. I actually solved the problem by forcing the value of the CostCenter field to be not-null in the Java Object. If you try to set the field to null, it uses "" instead:
protected String costCenter = "";
public void setCostCenter(String newValue) {
costCenter = (newValue == null) ? "" : newValue;
}
----- Original Message ----
From: Werner Guttmann <[email protected]>
To: [email protected]
Sent: Wed, October 14, 2009 4:04:20 AM
Subject: Re: [castor-dev] Force an element to be marshalled
Hi August,
if the following is an option to you, yes there is ....
<LineItem>
<ItemNumber>124029</ItemNumber>
<ItemQty>1</ItemQty>
<CostCenter xsi:nil=true" />
</LineItem>
Werner
August Detlefsen wrote:
> Is there any way to force an element to be marshalled to XML even if the field in the Java object is null or empty?
>
> I am marshalling XML to a remote web service that requires a CostCenter field in the XML, even if that field is null. Here is an example of the XML that is being produced:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <Order>
> <LineItem><ItemNumber>124029</ItemNumber><ItemQty>1</ItemQty><CostCenter>1234567.1234.123</CostCenter></LineItem>
> <LineItem><ItemNumber>122094</ItemNumber><ItemQty>1</ItemQty></LineItem>
> <LineItem><ItemNumber>119106</ItemNumber><ItemQty>1</ItemQty></LineItem>
> <LineItem><ItemNumber>119105</ItemNumber><ItemQty>1</ItemQty></LineItem>
> </Order>
>
> Only the first <LineItem> includes the <CostCenter> element, but I need all of them to include it, even if it is an empty item i.e. <CostCenter></CostCenter>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email