[英]Implementing abstract methods from abstract java class in generated jaxb class (inheritance)
[英]JAXB generated class field is abstract
我已经从xsd文件生成了类。
此类包含具有抽象类的字段。 这个抽象类有两个不同的实现。 我们称之为Impl1CLass和Impl2Class。
我无法修改xsd模式,也无法修改生成的类。
我需要做的就是当jaxb封送此类和abstract字段具有null值时,我需要获取以下内容:
<dep xsi:type="Impl1Class" xsi:nil="true"/>
生成的类中的Thi字段如下所示:
protected Dep dep;
Dep是抽象类。
所以我需要设置为nil并且类型是特定的(Impl1Class)
我试图用BoundType作为抽象类创建XmlAdapter,并且ValueType是JAXBElement,但是没有运气,因为它需要默认的非arg构造函数,但是JAXBElement没有这样的构造函数。
备注。 换句话说,我想在xsi:nil =“ true”时设置xsi:type。 我怎样才能做到这一点?
这是生成的类
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
name = "DepartmentKey"
)
@XmlSeeAlso({GroupDepartmentKey.class, EnterpriseDepartmentKey.class})
public abstract class DepartmentKey {
public DepartmentKey() {
}
}
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(
name = "GroupDepartmentKey",
propOrder = {"serviceProviderId", "groupId", "name"}
)
public class GroupDepartmentKey extends DepartmentKey {
@XmlElement(
required = true
)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String serviceProviderId;
@XmlElement(
required = true
)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String groupId;
@XmlElement(
required = true
)
@XmlJavaTypeAdapter(CollapsedStringAdapter.class)
protected String name;
......
}
在目标类中,没有任何注释的字段
protected DepartmentKey department;
拨打电话时,可以使用setter方法设置null。
Impl1Class impl1Class = new Impl1Class();
imple1Class.setDep(null);
可以使用二传手方法吗? 如果不是,则可能需要子类Impl1Class并将Dep设置为null。
希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.