I have a set of beans in a separate project that I can not change in both the JAPA and JACAB Annotations , And they are being used in a strict implementation. Most of my relationships are lazy-loaded, and I was hoping to get some more comprehensive controls on which the elements are actually martial for transport.
I've got modified MOXY Customer.java class below.
@ javax.xml.bind.annotation.XmlType @javax.xml.bind.annotation.XmlAccessorType (value = javax.xml.bind.annotation.XmlAccessType.PROPERTY) public class customer {personal String name; Private address addresses; Private list & amp; Phone number & gt; phone number; // getters and setters} I would have been able to use MOXY eclipselink-OXM mapping to control what would be martial, but it is not behaving As I expected. Using JAXB annotations, you declare an element (field or property) to be transient, but Eclipsellic-Oxm.XML only allows transient declarations on types. However, when I declare a transient type in a way, I get the following exceptions:
& Lt; Xml-element java-attribute = "address" xml-path = "contact-info / address" /> & Lt; / Java-Properties & gt; & Lt; / Java type & gt; & Lt; Java-type name = "example.gettingstarted.PhoneNumber" xml-transient = "true" /> & Lt; / Java-type & gt; & Lt; / XML-binding & gt; Exception:
Exceptions [EclipseLink-110] (eclipse stubborn services - 2.1.0.v20100614-r7608): org.eclipse.persistence.exceptions .writer exception exception description: The descriptor for the class is missing [example.gettingstarted.PhoneNumber]. Mapping: org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping [PHONENUMBERS] Descriptors: XMLDescriptor (example.gettingstarted.Customer -> [DatabaseTable (Customer)]) If I remove XML-transient attribute, or set it to false, as expected, the customer has been converted to XML. Is there any way I can suppress the marshaling of the phone number without modifying the customer's bean? Text after "
You can specify the use of the following mapping file to create a "phone number" property on the customer transient Do:
& lt ;? XML version = "1.0"? & Gt; & Lt; Xml-binding xmlns = "http://www.eclipse.org/eclipselink/xsds/persistence/oxm" & gt; & Lt; Java-type & gt; & Lt; Java-type name = "example.gettingstarted.Customer" & gt; & Lt; Xml-root-element / & gt; & Lt; Java-Properties & gt; & Lt; Xml-element java-attribute = "name" xml-path = "personal-info / name / text ()" /> & Lt; Xml-element java-attribute = "address" xml-path = "contact-info / address" /> & Lt; Xml-transient java-attribute = "phone number" /> & Lt; / Java-Properties & gt; & Lt; / Java type & gt; & Lt; / Java-type & gt; & Lt; / XML-binding & gt; For more information on MOXy's XML mapping file, see: -
Comments
Post a Comment