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 Blaise,

Thanks for the quick response.  I'm glad to hear that this use case will be
easier to handle in 2.0.  Since we cannot use the nightly builds, I have
created the bug report here:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=285926

Thanks!  :)

--Polly



Blaise Doughan wrote:
> 
> 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
>>>
>>>
>>>     
>>
>>   
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 

-- 
View this message in context: http://www.nabble.com/-MOXy--empty-string-tp22665748p24852689.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top