2014-06-17 2 views
2

내가 붙어 : 내 코드에서 오류를 볼하지만 ValueRequiredException 내 XML을 역 직렬화 할 때마다 점점 :간단한 XML : ValueRequiredException

(org.simpleframework.xml.Attribute @ 만족 할 수 없습니다 빈 = , name = epc_memory, required = true) 필드 'epcMemory'에 대한 protected byte [] de.sysvision.aviocheck.xml.generated 클래스의 de.sysvision.aviocheck.xml.generated.Object.epcMemory 14 행의 객체

저는 XML을 사용하고 있습니다 :

<?xml version="1.0" encoding="utf-8" ?> 
    <avio_check_inventory_data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
           xsi:noNamespaceSchemaLocation="AvioCheckInventoryData.xsd" 
           version="2.0"> 
     <avio_check_meta_data> 
     <original_timestamp>20130412152652000</original_timestamp> 
     <last_changed_timestamp>20130412152652000</last_changed_timestamp> 
     <content_type>master</content_type> 
     <ac_reg>D-AGWA</ac_reg> 
     </avio_check_meta_data> 
     <avio_check_payload> 
      <object epc_memory="3B3A00F1C30E008F4550430C30C30C40">  
      <type>LV</type>     
      <type_id>PAX</type_id>          
      <layer> <id>1</id> <region_id>A1</region_id> </layer> 
      <layer> <id>2</id> <region_id>A1</region_id> </layer> 
      <property id="MFR">78673</property>     
      <property id="PNO">S51150-6300</property>     
      <property id="DMF">20111101</property>     
      <property id="EXP">20161101</property>     
      <property id="LAC">1001A</property> 
      </object>     
     </avio_check_payload> 
    </avio_check_inventory_data> 
이 내 간단한 XML 객체 클래스입니다

:

내가 false로 epcMemory에서 "필요한"으로 설정하면
@Root(name = "object") 
    public class Object 
    { 
     @Attribute(required = false) 
     protected String noNamespaceSchemaLocation; 

     @Element(required = true) 
     protected String type; 
     @Element(name = "type_id", required = true) 
     protected String typeId; 
     protected List<Layer> layer; 
     protected List<Property> property; 
     @Attribute(name = "epc_memory", required = true) 
     protected byte[] epcMemory; 

     public String getType() { 
     return type; 
     } 

     public void setType(String value) { 
     this.type = value; 
     } 

     public String getTypeId() { 
     return typeId; 
     } 

     public void setTypeId(String value) { 
     this.typeId = value; 
     } 

     public List<Layer> getLayer() { 
     if (layer == null) { 
      layer = new ArrayList<Layer>(); 
     } 
     return this.layer; 
     } 

     public List<Property> getProperty() { 
     if (property == null) { 
      property = new ArrayList<Property>(); 
     } 
     return this.property; 
     } 

     public byte[] getEpcMemory() { 
     return epcMemory; 
     } 

     public void setEpcMemory(byte[] value) { 
     this.epcMemory = ((byte[]) value); 
     } 
    } 

,이 작품! 새로운 예외는 다음과 같습니다

필드 '유형'에 org.simpleframework.xml.Element (데이터 = 거짓, 이름 = 필요 = 사실, 유형 = 무효) @ 만족 할 수 없습니다

java.lang.String의 드를 보호 라인에서 클래스 de.sysvision.aviocheck.xml.generated.Object에 대한 .sysvision.aviocheck.xml.generated.Object.type 14

수 누구의 도움과 ANS 내가 잘못 걸 보여?

이 해당 XML 스키마입니다 :

<?xml version="1.0" encoding="utf-8"?> 
    <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> 
     <xs:simpleType name="DateTimeYYYYMMDDHHMMSSmmm"> 
     <xs:restriction base="xs:string"> 
      <xs:pattern value="\d{17}"/> 
     </xs:restriction> 
     </xs:simpleType> 

     <xs:simpleType name="content_type"> 
     <xs:list> 
      <xs:simpleType> 
      <xs:restriction base="xs:string"> 
       <xs:pattern value="master"/> 
       <xs:pattern value="update"/> 
      </xs:restriction> 
      </xs:simpleType> 
     </xs:list> 
     </xs:simpleType> 

     <xs:element name="avio_check_inventory_data"> 
     <xs:complexType> 
      <xs:sequence> 
      <xs:element name="avio_check_meta_data" minOccurs="1" maxOccurs="1"> 
       <xs:complexType> 
       <xs:sequence> 
        <xs:element name="original_timestamp" type="DateTimeYYYYMMDDHHMMSSmmm" minOccurs="1" maxOccurs="1" /> 
        <xs:element name="last_changed_timestamp" type="DateTimeYYYYMMDDHHMMSSmmm" minOccurs="0" maxOccurs="1"/> 
        <xs:element name="content_type" type="content_type" minOccurs="1" maxOccurs="1"/> 
        <xs:element name="ac_reg" type="xs:string" minOccurs="1" maxOccurs="1" /> 
       </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
      <xs:element name="avio_check_payload" minOccurs="1" maxOccurs="1"> 
       <xs:complexType> 
       <xs:sequence> 
        <xs:element name="object" minOccurs="1" maxOccurs="unbounded"> 
        <xs:complexType> 
         <xs:sequence> 
         <xs:element name="type" type="xs:string" minOccurs="1" maxOccurs="1" /> 
         <xs:element name="type_id" type="xs:string" minOccurs="1" maxOccurs="1" /> 
         <xs:element name="layer" minOccurs="0" maxOccurs="unbounded"> 
          <xs:complexType>       
          <xs:sequence> 
           <xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/> 
           <xs:element name="region_id" type="xs:string" minOccurs="1" maxOccurs="1"> 
           <xs:annotation> 
            <xs:documentation xml:lang="en"> 
            This is the same id as in used layout.xml! 
            </xs:documentation> 
           </xs:annotation> 
           </xs:element> 
          </xs:sequence> 
          </xs:complexType> 
         </xs:element>     
         <xs:element name="property" minOccurs="0" maxOccurs="unbounded"> 
          <xs:complexType> 
          <xs:simpleContent> 
           <xs:extension base="xs:string"> 
           <xs:attribute name="id" type="xs:string" /> 
           </xs:extension> 
          </xs:simpleContent> 
          </xs:complexType> 
         </xs:element> 
         </xs:sequence> 
         <xs:attribute name="epc_memory" type="xs:hexBinary" use="required" /> 
        </xs:complexType> 
        </xs:element> 
       </xs:sequence> 
       </xs:complexType> 
      </xs:element> 
      </xs:sequence> 
      <xs:attribute name="version" type="xs:decimal" use="required"/> 
     </xs:complexType> 
     </xs:element> 
    </xs:schema> 
+0

나는 XML 작업을 위해 뭔가 다른 것을 사용하므로 당신은 byte []가 아닌 String으로 속성 유형을 변경하려고 시도 했습니까? 동일한 오류가 발생합니까? – tomorrow

답변

2

대답은 간단했다 : 나는 = 진정한 인라인

@ElementList와 높이 요소의 주석을 사용했다 (인라인 = TRUE)

package de.sysvision.aviocheck.xml.generated; 

    import java.util.List; 

    import org.simpleframework.xml.Attribute; 
    import org.simpleframework.xml.Element; 
    import org.simpleframework.xml.ElementList; 
    import org.simpleframework.xml.Root; 

    @Root(strict = false) 
    public class Object 
    { 
     @Attribute(name = "epc_memory") 
     private String epcMemory; 

     @Element(required = false) 
     private String type; 

     @Element(name = "type_id") 
     private String typeId; 

     @ElementList(inline = true) 
     private List<Layer> layers; 

     @ElementList(inline = true) 
     private List<Property> properties; 

     public String getEpcMemory() { 
      return epcMemory; 
     } 

     public void setEpcMemory(String epcMemory) { 
      this.epcMemory = epcMemory; 
     } 

     public String getType() { 
      return type; 
     } 

     public void setType(String type) { 
      this.type = type; 
     } 

     public String getTypeId() { 
      return typeId; 
     } 

     public void setTypeId(String typeId) { 
      this.typeId = typeId; 
     } 

     public List<Layer> getLayers() { 
      return layers; 
     } 

     public void setLayers(List<Layer> layers) { 
      this.layers = layers; 
     } 

     public List<Property> getProperties() { 
      return properties; 
     } 

     public void setProperties(List<Property> properties) { 
      this.properties = properties; 
     } 

    }