JAXB Bean生成 [英] JAXB Bean Generation

查看:156
本文介绍了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.

有没有办法停止此行为?

谢谢。

UPDATE

解决了这个问题:xjb文件出现问题,generateIsSetMethod设置为是的。

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:


  1. 你可以指定一个模式注释:< ; jaxb:globalBindings generateIsSetMethod =true/>

  2. 您有一个外部绑定文件,指定:< jaxb:globalBindings generateIsSetMethod =true/>

  3. 您正在为Maven插件指定一个属性以生成 isSet 方法。

  1. You can a schema annotation that specifies: <jaxb:globalBindings generateIsSetMethod="true"/>
  2. You have an external binding file that specifies: <jaxb:globalBindings generateIsSetMethod="true"/>
  3. You are specifying a property to the Maven plug-in to generate the isSet methods.

这篇关于JAXB Bean生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆