2012-11-16 6 views
1

입니다. xml 바인딩을 사용하여지도를 언 마샬링해야하는데 오류가 발생합니다.JAXBException : 예기치 않은 요소 (uri : "", local : "workConfigRestWrapper"). 예상되는 요소는 <{}Config>, <{}MyMap>

MyMap.java :

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlRootElement(name = "MyMap") 
public class MyMap { 
@XmlElement(name = "Config", required = true) 
private final List<Config> config = new ArrayList<Config>(); 

public List<Config> getConfig() { 
    return this.config; 
} 
} 

MyAdaptor.java :

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

@XmlAttribute(name = "key", required = true) 
private final String key; 
@XmlAttribute(name = "value", required = true) 
private final String value; 

public Config(String key, String value) { 
    this.key = key; 
    this.value = value; 
} 

public Config() { 
    this.key = null; 
    this.value = null; 
} 

public String getKey() { 
    return key; 
} 

public String getValue() { 
    return value; 
} 
} 

클라이언트 코드 :

공용 클래스 MyAdaptor가 (때문에) XmlAdapter> {

@Override 
public MyMap marshal(Map<String,String> v) throws Exception { 
    MyMap myMap = new MyMap(); 
    List<Config> aList = myMap.getConfig(); 
    for (Map.Entry<String,String> e : v.entrySet()) { 
     aList.add(new Config(e.getKey(), e.getValue())); 
    } 
    return myMap; 
} 

@Override 
public Map<String,String> unmarshal(MyMap v) throws Exception { 
    Map<String,String> map = new HashMap<String,String>(); 
    for (Config e : v.getConfig()) { 
     map.put(e.getKey(), e.getValue()); 
    } 
    return map; 
} 
} 

Config.java 확장

  String getConfigurationMethod = baseUrl + "getConfiguration"; 
      byte[] getConfigurationResponse = (byte[]) this 
       .sendGetMethod(getConfigurationMethod); 
      unmarshaller = this.getUnmarshaller(MyMap.class); 
    reader = new StringReader(new String(getConfigurationResponse)); 
    MyMap myMap = (MyMap) unmarshaller.unmarshal(reader); 

오류 메시지 :

JAXBException에 : 예기치 않은 요소 (URI : ""지역 "workConfigRestWrapper"). 예상되는 요소는 < {} Config>, < {} MyMap> 입니다. javax.xml.bind.UnmarshalException : 예기치 않은 요소 (uri : "", local : "workConfigRestWrapper")입니다. 예상되는 요소는 < {} Config>, < {} MyMap> com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent (UnmarshallingContext.java:662) at com.sun.xml.bind입니다. v2.runtime.unmarshaller.Loader.reportError (Loader.java:258)(com.sun.xml.bind.v2.runtime.unmarshaller.Loader.reportError (Loader.java:253) , com.sun.xml). bind.v2.runtime.unmarshaller.Loader.reportUnexpectedChildElement (Loader.java:120) com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext $ DefaultRootLoader.childElement (UnmarshallingContext.java:1063) COM에서 에서 . com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.startEl의 에서 sunsite.bind.v2. (UnmarshallingContext.java:480) com.sun.xml.bind.v2.runtime.unmarshaller.SAXConnector.startElement (SAXConnector.java:150) at org.apache.xerces.parsers.AbstractSAXParser.startElement (알 수없는 소스) org.apache.xerces.impl.XMLDocumentFragmentScannerImpl $ FragmentContentDispatcher에서 org.apache.xerces.impl.XMLNSDocumentScannerImpl $ NSContentDispatcher.scanRootElementHook (알 수없는 소스) 에서 org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement (알 수없는 소스) 에서 .dispatch (알 소스)에 org.apache.xerces.parsers.XML11Configuration.parse org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument (알 소스) (알 소스)에 org.apache.xerces.parsers 에서 . XML11Configuration.parse (알 수없는 소스)org.apache.xerces.jaxp.SAXParserImpl $ JAXPSAXParser.parse에서 org.apache.xerces.parsers.AbstractSAXParser.parse (알 수없는 소스) 에서 org.apache.xerces.parsers.XMLParser.parse (알 수없는 소스) 에서 16,(알 수없는 소스) com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0 (UnmarshallerImpl.java:217) com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal (UnmarshallerImpl 된 .java : javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal (AbstractUnmarshallerImpl.java:194) 에서 javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal (AbstractUnmarshallerImpl.java:137) 189)에서 com.ge .dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.execute (CustomerRemoteAgent.java:193) at com.ge.dsp.iw orkRemote.remoteAgents.CustomerRemoteAgent.main (CustomerRemoteAgent.자바 : 나는 래퍼 클래스 대신에는 myMap 사용 된

byte[] getConfigurationResponse = (byte[]) this.util 
      .sendGetMethod(this.getConfigurationMethod); 

    Unmarshaller unmarshaller = this.getUnmarshaller(**WorkConfigRestWrapper.class**); 
    StringReader reader = new StringReader(new String(getConfigurationResponse)); 
    **WorkConfigRestWrapper wrk** = (WorkConfigRestWrapper) unmarshaller 
      .unmarshal(reader); 

: 364)

답변

1

나는대로 클라이언트 코드를 수정했습니다. :(

+0

같은 문제가, 나 또한 오전 주석 @XmlType을 넣어보십시오 향함, 해결책을 찾는 것은 당신에게 알려줄 것입니다. – sandejai

0

은 (propOrder = {})를 MyMap.java 클래스에. 당신이 어떤 순서로 파일의 내용을 읽을 수있는이 유형을 사용하여 .