是否可以使用JAXB根据xml的属性将xml解组为特定的Java类?
<shapes>
<shape type="square" points="4" square-specific-attribute="foo" />
<shape type="triangle" points="3" triangle-specific-attribute="bar" />
</shapes>
Run Code Online (Sandbox Code Playgroud)
我想有一个包含三角形和正方形的Shape对象列表,每个对象都有自己的特定于形状的属性.IE:
abstract class Shape {
int points;
//...etc
}
class Square extends Shape {
String square-specific-attribute;
//...etc
}
class Triangle extends Shape {
String triangle-specific-attribute;
//...etc
}
Run Code Online (Sandbox Code Playgroud)
我目前只是将所有属性放在一个大的"Shape"类中,并且它不太理想.
如果形状被恰当地命名为xml元素,我可以让它工作,但不幸的是我无法控制我正在检索的xml.
谢谢!