Hi Blaise,
I tried to do what you suggested with option #1 but am not having any
success (using EL 1.1.2). My converter is not getting called. My test XML
has an empty element like:
<CareOfName></CareOfName>
After some trial and error, I created this deployment project.xml file
snippet:
<attribute-mapping xsi:type="xml-direct-mapping">
<attribute-name>careOfName</attribute-name>
<field name="CareOfName/text()" xsi:type="node"/>
<null-policy xsi:type="null-policy">
<null-representation-for-xml
xsi:type="marshal-null-representation">ABSENT_NODE</null-representation-for-xml>
<is-set-performed-for-absent-node>false</is-set-performed-for-absent-node>
</null-policy>
</attribute-mapping>
Usually when I unmarshal an element that has a value, the flow is that
UnmarshalRecord.endElement()'s second "if" statement calls into
XMLDirectMappingNodeValue.endElement(), which then calls the converter. But
when I'm unmarshalling this "CareOfName" element, the second "if" fails
because xpathNode.getUnmarshalNodeValue() is null. So it never goes inside
the "if" to call the converter.
Is there something else that I should be setting?
Thanks!
--Polly
Blaise Doughan wrote:
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
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users