JAXB Bean Generation(JAXB Bean 生成)
问题描述
我正在使用 JAXB 使用 Maven 中的 JAXB 插件从 XSD 生成 bean.这工作正常,希望代码包含每个字段的 isSetXXXXXX() 方法.
I am using JAXB for generating beans from XSD's using a JAXB plugin in Maven. This is working fine, expect that the code contains isSetXXXXXX() methods for each field.
例如
对于字段 firstName,它会生成以下代码:
for a field firstName, it is producing the following code:
@XmlElement(name = "FirstName", required = true)
protected String firstName;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.token = firstName;
}
public boolean isSetFirstName() {
return (this.firstName!= null);
}
这个 isSetFirstName() 方法会导致问题,我不希望 JAXB 生成这些问题.
This isSetFirstName() method is causing issues and I don't want JAXB to generate these.
有没有办法阻止这种行为?
谢谢.
更新
解决了这个问题:问题出在 xjb 文件中,generateIsSetMethod 设置为 true.
Solved this: Problem was in the xjb file, generateIsSetMethod was set to true.
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings generateIsSetMethod="true">
bindingStyle="modelGroupBinding"
choiceContentProperty="true" >
<xjc:serializable uid="12343"/>
<jaxb:javaType name="short"
xmlType="xs:long"
printMethod="javax.xml.bind.DatatypeConverter.printShort"
parseMethod="javax.xml.bind.DatatypeConverter.parseShort"/>
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
这也回答了我的上一个问题.
推荐答案
默认情况下,JAXB (JSR-222) 实现不会生成 isSet 方法.由于您得到它们,因此必须满足以下条件之一:
By default a JAXB (JSR-222) implementation will not generate isSet methods. Since you are getting them one of the following must be true:
- 您可以在架构注释中指定:
<jaxb:globalBindings generateIsSetMethod="true"/> - 您有一个外部绑定文件指定:
<jaxb:globalBindings generateIsSetMethod="true"/> - 您正在为 Maven 插件指定一个属性以生成
isSet方法.
这篇关于JAXB Bean 生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JAXB Bean 生成
基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
