Mapping a Java property to several xml attributes using JAXB and MOXy?

Up vote 1 down vote favorite 1 share g+ share fb share tw.

I have a simple class CustomQuoteRequest: public class CustomQuoteRequest { private String requestId; private String currencyPairCode; public String getRequestId() { return requestId; } public void setRequestId(String requestId) { this. RequestId = requestId; } public String getCurrencyPairCode() { return currencyPairCode; } public void setCurrencyPairCode(String currencyPairCode) { this. CurrencyPairCode = currencyPairCode; } } I would like to map currencyPairCode to two different attributes in the xml.

This is the MOXy mapping file I am using: However the second xml-element seems to override the previous one. Any ideas? Thanks a lot java jaxb eclipselink moxy link|improve this question edited Oct 19 '10 at 1:09Blaise Doughan23k51533 asked Oct 19 '10 at 0:44Sergio284.

EclipseLink MOXy 2.1. X In EclipseLink 2.1. X you can use an XML Customizer to accomplish this. Your external metadata would look like the following: In the customizer we'll add a second mapping for the currencyCodePair property. We will need to indicate that this mapping is write only.

The implementation of the XML customizer would look like the following: package customizer; import org.eclipse.persistence.config. DescriptorCustomizer; import org.eclipse.persistence.descriptors. ClassDescriptor; import org.eclipse.persistence.oxm.mappings.

XMLDirectMapping; public class CustomQuoteRequestCustomizer implements DescriptorCustomizer { public void customize(ClassDescriptor descriptor) throws Exception { XMLDirectMapping currencyPairCodeLegMapping = new XMLDirectMapping(); currencyPairCodeLegMapping. SetAttributeName("currencyPairCode"); currencyPairCodeLegMapping. SetXPath("QuotReq/QuoteReq/Leg/Leg/@Sym"); currencyPairCodeLegMapping.

SetIsWriteOnly(true); descriptor. AddMapping(currencyPairCodeLegMapping); } } EclipseLink MOXy 2.2 In the upcoming EclipseLink 2.2 release you will be able to do this using just the externalized metadata: The following bug can be used to track this support: https://bugs.eclipse.org/328135.

Fantastic, thanks a lot for that! – Sergio Oct 19 '10 at 20:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions