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,

You have found a bug in the EclipseLink 1.1.2 release.  This has been fixed in the 2.0 stream (the nightly downloads are available below).  If you need this included in a patch release could you enter a bug?

http://www.eclipse.org/eclipselink/downloads/nightly.php

In EclipseLink 2.0 you will not need a converter.  You will be able to set the "setNullRepresentedByEmptyNode" on the null policy to false and for Strings the value will unmarshal as "" automatically.

-Blaise

polly.c.chang wrote:
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


    
  

Back to the top