JAXB - XJC 설정 키 값 쌍 변환 비트 직접 바인딩에 대한 맵 생성하지 않음

StackOverflow https://stackoverflow.com//questions/20052279

  •  26-12-2019
  •  | 
  •  

문제

키-값 쌍 변환 목록에지도를 생성하지 않도록 XJC를 강제로 할 수 있습니까?

jaxb 주석을 찍을 때

@XmlRootElement
public class Customer {

private Map<String, Address> addressMap = new HashMap<String, Address>();

public Map<String, Address> getAddressMap() {
    return addressMap;
}

public void setAddressMap(Map<String, Address> addressMap) {
    this.addressMap = addressMap;
}

}
.

및 schemagen을 통해 스키마 생성 xsd 스키마 다음을 수행합니다.

  <xs:element name="customer" type="customer"/>

<xs:complexType name="address">
<xs:sequence>
  <xs:element name="street" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

 <xs:complexType name="customer">
<xs:sequence>
  <xs:element name="addressMap">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="key" minOccurs="0" type="xs:string"/>
              <xs:element name="value" minOccurs="0" type="address"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:sequence>
.

jaxb 주석이 지정된 클래스를 생성 할 때 xjc를 통해 지정된 바인딩을 사용하여 :

    <jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.1">
    <jaxb:bindings schemaLocation="schema1.xsd"> 
    <jaxb:bindings node="//xs:complexType[@name='customer']//xs:element[@name='addressMap']">
     <jaxb:property>
      <jaxb:baseType name="java.util.HashMap&lt;String,Address&gt;" />
     </jaxb:property>
     </jaxb:bindings>
     </jaxb:bindings>

  </jaxb:bindings>
.

나는 돌아올 것이다 :

    @XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
    "addressMap"
})
public class Customer {

    @XmlElement(required = true)
    @XmlJavaTypeAdapter(MapAdapter.class)
    protected HashMap<String, Address> addressMap;

    public HashMap<String, Address> getAddressMap() {
        return addressMap;
    }

    public void setAddressMap(HashMap<String, Address> value) {
        this.addressMap = value;
    }

    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "entry"
    })
    public static class AddressMap {

        protected List<Customer.AddressMap.Entry> entry;

        public List<Customer.AddressMap.Entry> getEntry() {
            if (entry == null) {
                entry = new ArrayList<Customer.AddressMap.Entry>();
            }
            return this.entry;
        }

        @XmlAccessorType(XmlAccessType.FIELD)
        @XmlType(name = "", propOrder = {
            "key",
            "value"
        })
        public static class Entry {

            protected java.lang.String key;
            protected blog.map.generated.Address value;

            public java.lang.String getKey() {
                return key;
            }

            public void setKey(java.lang.String value) {
                this.key = value;
            }

            public blog.map.generated.Address getValue() {
                return value;
            }

            public void setValue(blog.map.generated.Address value) {
                this.value = value;
            }
        }
    }
}
.

그것은 내가 정확히 원했던 것이 아닙니다.내 "원래"입력을 얻을 수있는 방법이 있습니까?

도움이 되었습니까?

해결책

표준이 없습니다 jaxb (JSR-222) XML 스키마에서 다음 클래스를 생성하는 방법.

@XmlRootElement
public class Customer {

    private Map<String, Address> addressMap = new HashMap<String, Address>();

    public Map<String, Address> getAddressMap() {
        return addressMap;
    }

    public void setAddressMap(Map<String, Address> addressMap) {
        this.addressMap = addressMap;
    }

}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top