Hi Adriano,
This appears to be a valid MOXy bug. There is an issue with our
Self Mapping support (the creditor field is mapped to '.') where
both Creditor and PaymentInf both have an xml path ('field name'
in the workbench mapping file) ending in 'id/text()'.
I have opened an EclipseLink bug to track this issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=333306
In the meantime you can try mapping one of the 'id' fields to a
different XPath as you suggested, such as 'pid/text()' for the
PaymentInf 'id' field, or map one of them to an attribute, such as 'CreditorFrstName/@id' for the Creditor 'id'
field.
Regards,
Dave
On 29/12/2010 4:12 AM, Adriano Daniele wrote:
MOXy JAXB Eclipselink Workbench - wrong unmarshall
Hello,
can you please help me to understand what's wrong in my simple
unmarshall example?
Libraries used:
- jdk 1.5.0_16
- EclipseLink 2.2.0
- javax.xml.stream_1.0.1
- javax.xml.bind_2.2.0
Xml file:
<PaymentInf>
<id>pmtid</id>
<PmtInf>
<service>
<id>SEPA</id>
</service>
<amount>
<val>1</val>
</amount>
<date>2010-12-27</date>
</PmtInf>
<CreditorFrstName>
<cd>myfrstname</cd>
<id>frstId</id>
</CreditorFrstName>
<CreditorLstName>
<cd>mylastname</cd>
</CreditorLstName>
</PaymentInf>
java classes (getter and setter are here hidden):
public class PaymentInf {
private String id;
private String service;
private BigDecimal amount;
private Date date;
private Creditor creditor;
}
public class Creditor {
private String firstName;
private String lastName;
private String id;
}
Test code:
JAXBContext context =
JAXBContextFactory.createContext("payment",
getClass().getClassLoader());
InputStream payment =
getClass().getClassLoader().getResourceAsStream("payment.xml");
Unmarshaller unmarshaller = context.createUnmarshaller();
PaymentInf pmt = (PaymentInf) unmarshaller.unmarshal(payment);
It works properly only if i map all xml fields and only if
<id> tag is not duplicated (i have to change service id
tag to idserv and creditorFrstName id tag to idcred).
If i didn't map the <service> tag and <id> field
is duplicated then:
- amount is null
- date is null
- id is null
- service is null
- creditor firstName is properly unmarshalled
- creditor lastName is properly unmarshalled
- creditor id is "frstIdfrstId" (duplicated)
If i didn't map the <service> tag and <id> field
is not duplicated then:
- amount is null
- date is null
- id is properly unmarshalled
- service is null
- creditor firstName is properly unmarshalled
- creditor lastName is properly unmarshalled
- creditor id is is properly unmarshalled
What is wrong?
Thank you for your attention,
Daniele
p.s. Here the xml mapping generated by Eclipselink Workbench
used in the test:
<?xml version="1.0" encoding="UTF-8"?>
<object-persistence xmlns="http://www.eclipse.org/eclipselink/xsds/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:eclipselink="http://www.eclipse.org/eclipselink/xsds/persistence"
version="Eclipse Persistence Services -
2.1.2.v20101206-r8635">
<name>payment</name>
<class-mapping-descriptors>
<class-mapping-descriptor
xsi:type="xml-class-mapping-descriptor">
<class>dto.PaymentInf</class>
<alias>PaymentInf</alias>
<events/>
<querying/>
<attribute-mappings>
<attribute-mapping
xsi:type="xml-composite-object-mapping">
<attribute-name>creditor</attribute-name>
<reference-class>dto.Creditor</reference-class>
<field name="." xsi:type="node"/>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>id</attribute-name>
<field name="id/text()" xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>service</attribute-name>
<field name="PmtInf/service/id/text()"
xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>amount</attribute-name>
<field name="PmtInf/amount/val/text()"
xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>date</attribute-name>
<field name="PmtInf/date/text()"
xsi:type="node">
<schema-type>{http://www.w3.org/2001/XMLSchema}date</schema-type>
</field>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
</attribute-mappings>
<descriptor-type>aggregate</descriptor-type>
<instantiation/>
<copying xsi:type="instantiation-copy-policy"/>
<default-root-element>PaymentInf</default-root-element>
<default-root-element-field name="PaymentInf"/>
</class-mapping-descriptor>
<class-mapping-descriptor
xsi:type="xml-class-mapping-descriptor">
<class>dto.Creditor</class>
<alias>Creditor</alias>
<events/>
<querying/>
<attribute-mappings>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>firstName</attribute-name>
<field name="CreditorFrstName/cd/text()"
xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>id</attribute-name>
<field name="CreditorFrstName/id/text()"
xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
<attribute-mapping
xsi:type="xml-direct-mapping">
<attribute-name>lastName</attribute-name>
<field name="CreditorLstName/cd/text()"
xsi:type="node"/>
<null-policy xsi:type="null-policy">
<empty-node-represents-null>true</empty-node-represents-null>
<null-representation-for-xml>ABSENT_NODE</null-representation-for-xml>
</null-policy>
</attribute-mapping>
</attribute-mappings>
<descriptor-type>aggregate</descriptor-type>
<instantiation/>
<copying xsi:type="instantiation-copy-policy"/>
<should-preserve-document>true</should-preserve-document>
</class-mapping-descriptor>
</class-mapping-descriptors>
<login xsi:type="xml-login">
<platform-class>org.eclipse.persistence.oxm.platform.SAXPlatform</platform-class>
<user-name></user-name>
</login>
</object-persistence>
Here is session.xml:
<?xml version="1.0" encoding="UTF-8"?>
<sessions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="2.1.2">
<session xsi:type="database-session">
<name>payment</name>
<event-listener-classes/>
<logging xsi:type="eclipselink-log"/>
<primary-project
xsi:type="xml">mapping.xml</primary-project>
<login xsi:type="xml-login">
<platform-class>org.eclipse.persistence.oxm.platform.SAXPlatform</platform-class>
<document-preservation-policy
xsi:type="no-document-preservation-policy">
<node-ordering-policy
xsi:type="append-new-elements-ordering-policy"/>
</document-preservation-policy>
</login>
</session>
</sessions>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--
David McCann | Principal Software Engineer |
+6132884636
Oracle Server Technologies,
EclipseLink Product
ORACLE Canada | 45 O'Connor St., Suite 400 | Ottawa, Ontario |
K1P 1A4
|
Oracle is
committed to developing practices and products that
help protect the environment |
|