java两种不同的模式和JAXB封送器
假设我们有带模式的XML consnensual和带一些公共字段的Java类:
<objectFromSchema1>
<element1/>
<commonElement1/>
<commonElement2/>
<element2/>
</objectFromSchema1>
public class X {
private String element1;
private String commonElement1;
private String commonElement2;
private String element2;
}
将此类XML解组为Java对象是一种很好的方法吗?这意味着:转换所有一致同意的字段,并在rest上设置null
# 1 楼答案
“是的”
如果你有一个xsd,你也可以通过
<artifactId>maven-jaxb2-plugin</artifactId>
maven插件自动生成这些类你们班的一个例子
使用它的主要方法
输出
# 2 楼答案
答案是“是的”。这就是JAXB的工作方式。看看基本的JAXB教程,例如https://jaxb.java.net/tutorial/
http://docs.oracle.com/javase/tutorial/jaxb/intro/
http://www.vogella.com/tutorials/JAXB/article.html