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 生成


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01