zoukankan      html  css  js  c++  java
  • jaxb异常 Class has two properties of the same name username

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlAttribute;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlRootElement;

    @XmlRootElement(name = "User")
    @XmlAccessorType(XmlAccessType.FIELD)
    public class User {

    private String id;

    private String username;

    private String password;

    private Expense e;

    public String getId() {
    return id;
    }

    public void setId(String id) {
    this.id = id;
    }

    @XmlAttribute(name = "ID")
    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    }

    public String getPassword() {
    return password;
    }

    public void setPassword(String password) {
    this.password = password;
    }

    }

    This is a JAXB configuration issue, the JAXB runtime thinks there are  
    two properties to be serialized with the same name, one that is the  
    protected and field and one which is the JavaBean property method.

     "If JAXB binds a class to XML, then, by default, all public members  
    will be bound, i.e., public getter and setter
        pairs, or public fields. Any protected, package-visible or private  
    member is bound if it is annotated with a suitable
        annotation such as XmlElement or XmlAttribute."

    If you annotate your Artifact class with the annotation:

       @XmlAccessorType(XmlAccessType.FIELD)

    then you do not need to annotate the fields with @XmlElement and the  
    setter/getter methods will be ignored.

    意思是jaxb的配置问题,成员变量的修饰符为public的可以不设置

     @XmlAccessorType(XmlAccessType.FIELD)
    如果不是public的字段需要设置此属性。

  • 相关阅读:
    Vue2.0 【第二季】第2节 Vue.extend构造器的延伸
    Vue2.0 【第二季】第1节 Vue.directive自定义指令
    Vue2.0 【第一季】第8节 v-pre & v-cloak & v-once
    Vue2.0 【第一季】第7节 v-bind指令
    c# tcp协议
    easyui笔记
    asp.net get中文传值乱码
    asp.net 调试,Web 服务器被配置为不列出此目录的内容。
    金蝶API 官方demo报错,解决方案
    hbuilder拍照上传,与asp.net服务器获取并保存
  • 原文地址:https://www.cnblogs.com/fuyuanming/p/4848349.html
Copyright © 2011-2022 走看看