Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] [MOXy] empty string

Hi Polly,

The relevant method is "setSetPerformedForAbsentNode(boolean)"
http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/oxm/mappings/nullpolicy/NullPolicy.html#setSetPerformedForAbsentNode(boolean)

You will want to configure this parameter to be false.  Then EclipseLink will not perform a set operation for missing tags.  For the "" porting you have two options:
  1. Use a converter with the mapping, if the field value is null then return "" as the attribute value.
  2. Use method accessing on the mapping (configure the mapping to use the get/set methods instead of the attribute directly).  Then put logic on the set method to convert null to "".  Since EclipseLink won't perform a set for missing tags you'll know that the set to null calls correspond only to empty tags.
-Blaise

polly.c.chang wrote:
Hi,

I have a situation where we need to distinguish between empty tags vs.
missing tags.  The rules are:

For all String types:
* If the XML has <description></description>, that is supposed to mean empty
string ("").
* If the XML has no "description" tag, that is supposed to mean null.
* And vice versa for marshalling.

I looked at the javadoc and found that I might need to set a NullPolicy:
http://www.eclipse.org/eclipselink/api/1.1/org/eclipse/persistence/oxm/mappings/nullpolicy/NullPolicy.html

I am still confused after reading the documentation though.  How do I tell
EclipseLink that empty string means empty tags?  

Thanks!
--Polly
  

Back to the top