Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] How to get MOXy to trim the text values?

Hi Matt,

I was going to wait for the enhancement request to be implemented, but that
has moved to version 2.0.  So now I need to implement a fix for our project. 

Can you give me some advice as to whether the Converter or the
AttributeAccessor is better?  It seems to me that if I go the Converter
route, it might interfere with enums.  So if I go the AttributeAccessor
route, I need to create two accessors--one to extend
InstanceVariableAttributeAccessor and one to extend MethodAttributeAccessor. 
Then I would override the setAttributeValueInObject() method.  Does that
sound right?

Just as an example, when I *don't* trim the string, I get this error with
enums.  Which approach do you recommend for fixing this?


Caused by: Exception [EclipseLink-116] (Eclipse Persistence Services - 1.0.2
(Build 20081024)): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: No conversion value provided for the value [
            ] in field [text()].
Descriptor: XMLDescriptor(com.infor.common.model.fields.ResponseCode --> [])


Matt MacIvor wrote:
> Hi Polly,
> Currently EclipseLink MOXy considers everything inside an element to be 
> significant, and therefore doesn't trim the value. You can work around 
> this in a couple of ways.
> One would be to implement a Converter (see 
> org.eclipse.persistence.mappings.converters.Converter interface) and add 
> this to your mapping with a session customization. This would allow you 
> to manually trim the value before it's set in your object. You could 
> also do this with a custom attribute accessor. (see 
> org.eclipse.persistence.mappings.AttributeAccessor).
> I agree there should be an easier way to do this. We should be able to 
> just add a flag on XMLDirectMapping to indicate that string values 
> should be trimmed.
> Could you enter an enhancement request to this effect?
> Thanks,
> -Matt
> amphoras wrote:
>>I mapped a field in my Java class to an XPath like
>>I find that when the XML looks like this:
>>                            <CountryCode listID='' listAgencyID=''
>>listAgencyName='' listName='' listVersionID='' name='' languageID=''
>>listURI='' listSchemeURI=''>
>>                            USA
>>                            </CountryCode>
>>The value that gets unmarshalled is "                            USA". 
>>those spaces that were used for formatting are preserved.  Is there a way
>>configure EclipseLink to trim the spaces on either end of the string and
>>just give me "USA"?
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx

View this message in context:
Sent from the EclipseLink - Users mailing list archive at

Back to the top