JAXB-以小写字母开头的重复元素
我提供的以下测试在WildFly 13(JEE 7/JAXB v2.2)下正确运行。 在WildFly 19(JEE8/JAXB v2.3)下,由于我附加的错误输出而失败JAXB-以小写字母开头的重复元素,jaxb,java-ee-7,java-ee-8,Jaxb,Java Ee 7,Java Ee 8,我提供的以下测试在WildFly 13(JEE 7/JAXB v2.2)下正确运行。 在WildFly 19(JEE8/JAXB v2.3)下,由于我附加的错误输出而失败 @Test public void test_marshaller() throws JAXBException { SPC spc = new SPC(); spc.setAdminInfo(new AdminInfo()); spc.getAdminInfo().setAuthorisation(n
@Test
public void test_marshaller() throws JAXBException {
SPC spc = new SPC();
spc.setAdminInfo(new AdminInfo());
spc.getAdminInfo().setAuthorisation(new Authorisation());
spc.setLang(LanguageCode.valueOf("en"));
JAXBContext context = JAXBContext.newInstance(SPC.class);
Marshaller marshaller = context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
System.out.println("Marshaller package is " + Marshaller.class.getPackage());
System.out.println("Marshaller generic string is " + marshaller.getClass().toGenericString());
System.out.println("Marshaller class Name is " + marshaller.getClass().getName());
System.out.println("Context Name is " + context.getClass().getName());
marshaller.marshal(spc, System.out);
}
在WF 13下,我收到以下正确输出:
<ns4:SPC xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:ns4="http://echa.europa.eu/schema/spc/1.0/" xml:lang="en">
<ns4:AdminInfo>
<ns4:Authorisation>
<ns4:Date xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ns4:Expiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns4:Authorisation>
</ns4:AdminInfo>
<ns4:AuthorisedUses/>
</ns4:SPC>
你的班级是什么样的?您是从XSD生成的还是手动编写的?这对您有帮助吗?所有
@XmlElement
都作为副本生成(即使它们的首字母大写相同),所有@XmlAttribute
都作为具有相同值的属性和元素生成。SPC类的XML accesor类型是@XmlAccessorType(XmlAccessType.PROPERTY)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns4:SPC xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" xmlns:ns3="http://www.w3.org/1999/xhtml" xmlns:ns4="http://echa.europa.eu/schema/spc/1.0/" xml:lang="en">
<ns4:adminInfo>
<ns4:Authorisation>
<ns4:Date xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ns4:Expiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns4:Authorisation>
</ns4:adminInfo>
<ns4:lang>
<representation>en</representation>
</ns4:lang>
<ns4:AdminInfo>
<ns4:Authorisation>
<ns4:Date xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ns4:Expiry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns4:Authorisation>
</ns4:AdminInfo>
<ns4:AuthorisedUses/>
</ns4:SPC>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.9.1</version>
<configuration>
...
<plugins>
<plugin>
<groupId>com.github.jaxb-xew-plugin</groupId>
<artifactId>jaxb-xew-plugin</artifactId>
<version>1.6</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.0</version>
</plugin>
</plugins>
</configuration>