【发布时间】:2021-05-11 11:37:37
【问题描述】:
JAXB 似乎忽略了@XmlAttribute 注释并且没有填充attributeName 和attributeValue 属性。
你能帮我解决这个问题吗?
XML:
<?xml version="1.0" encoding="UTF-8"?>
<Product>
<ProductCode>PRD191_5</ProductCode>
<AttrList>
<element Name="Toy Type" Value="Quadrocopter"/>
<element Name="Engine Type" Value="Electric Engine"/>
<element Name="Build Type" Value="Ready-To-Fly"/>
</AttrList>
</Product>
Java 类:
@XmlRootElement(name = "Product")
@XmlAccessorType(XmlAccessType.FIELD)
public class Product {
@XmlElement(name = "ProductCode")
private String productCode;
@XmlElement(name = "AttrList")
private List<Attribute> attrList = null;
}
@XmlRootElement(name = "element")
@XmlAccessorType(XmlAccessType.FIELD)
public class Attribute {
@XmlElement(name="element")
@Column
private String element;
@XmlAttribute(name = "Name", required=true)
@Column
private String attributeName;
@XmlAttribute(name = "Value", required=true)
@Column
private String attributeValue;
}
Maven 依赖:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
【问题讨论】:
标签: java xml annotations jaxb