I 다음 XML 엔티티가 :ClassCastException이 비 정렬 화 JSON
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement
public class DocumentDossier {
private XdsJsonSubmissionSet submissionSet;
private XdsJsonDocument documentEntry;
private List<XdsJsonFolder> folder;
private List<XdsJsonAssociation> association;
...
그리고 나는 다음과 같은 방식으로 JSON 파일 비 직렬화하기 위해 노력하고있어 : 나는 비 직렬화 할 필요가
String content = IOUtils.toString(is);
JSONObject obj = new JSONObject(content);
Configuration config = new Configuration();
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
XMLStreamReader xmlStreamReader = new MappedXMLStreamReader(obj, con);
JAXBContext jc = JAXBContext.newInstance(DocumentDossier.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
DocumentDossier result = (DocumentDossier) unmarshaller.unmarshal(xmlStreamReader);
하지만 JSON을 루트 노드가 없으므로 루트 노드입니다. 여기에 JSON은 문제의 :
{
"submissionSet": {...},
"documentEntry": {...},
"association": {...}
}
이 코드를 사용하여, 나는 다음과 같은 오류 얻을 :
java.lang.ClassCastException: XdsJsonSubmissionSet cannot be cast to DocumentDossier
이 문제점은 무엇입니까?
귀하의 질문에 이해가되지 않습니다 : 묵시적 루트 노드가 있습니다 (외부 '{}'는 사실 JSON "객체"입니다) 당신은 그 요소를'DocumentDossier'의 필드에 매핑해야합니다. 그래서 이것은 이미 작동해야합니다. 오류가 있습니까? 또는 구체적으로 건너 뛰고 싶은 점은 무엇입니까? –
나는 다음과 같은 오류가 발생합니다 : XdsJsonSubmissionSet이 DocumentDossier 캐스트 할 수없는 내가 내 JSON 개체가 { "documentDossier"...}에 싸여 데 건너 뛰려면 : java.lang.ClassCastException가, 그래서 내 웹 서비스 것 내가 게시 한 것과 같은 JSON 객체를받을 수 있어야합니다. – user2451415
JSON을'{ "documentDossier": ...} "로 감싸는 경우, JSON을 구문 분석 할 수 있으려면'DocumentDossier'를 래핑하는 다른 Java 클래스가 필요합니다. 위의 JSON은 이미'DocumentDossier'에 매핑되어 있어야합니다. 오류에는 다른 이유가 있어야합니다. –