jaxbを使用してxml応答をjavaオブジェクトに変換しようとすると、次のエラーが発生します
javax.xml.bind.UnmarshalException: unexpected element (uri:"http://SOMETHING/doc/2006-03-01/", local:"Name"). Expected elements are <{}Name>,<{}IsTruncated>,<{}MaxKeys>,<{}Contents>,<{}Prefix>,<{}Marker>
これが私のXMLです:
<ListBucketResult xmlns="http://something/doc/2006-03-01/">
<Name>test2</Name>
<Prefix/>
<Marker/>
<MaxKeys>3</MaxKeys>
<IsTruncated>false</IsTruncated>
<Contents>
<Key>metadata.xml</Key>
<LastModified>2012-09-04T08:29:36.000Z</LastModified>
<ETag>6b836fd43c402681506926b2248ec418</ETag>
<Size>3258</Size>
<StorageClass>STANDARD</StorageClass>
</Contents>
</ListBucketResult>
そして私のJavaオブジェクトクラスはこのようなものです
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"name",
"prefix",
"marker",
"maxKeys",
"isTruncated",
"contents"
})
@XmlRootElement(name = "ListBucketResult")
public class ListBucketResult {
@XmlElement(name = "Name", required = true)
protected String name;
@XmlElement(name = "Prefix", required = true)
protected String prefix;
@XmlElement(name = "Marker", required = true)
protected String marker;
@XmlElement(name = "MaxKeys")
protected int maxKeys;
@XmlElement(name = "IsTruncated")
protected boolean isTruncated;
@XmlElement(name = "Contents", required = true)
protected ListBucketResult.Contents contents;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"key",
"lastModified",
"eTag",
"size",
"storageClass"
})
public static class Contents {
@XmlElement(name = "Key", required = true)
protected String key;
@XmlElement(name = "LastModified", required = true)
@XmlSchemaType(name = "dateTime")
protected XMLGregorianCalendar lastModified;
@XmlElement(name = "ETag", required = true)
protected String eTag;
@XmlElement(name = "Size")
protected int size;
@XmlElement(name = "StorageClass", required = true)
protected String storageClass;
そして最後に私のアンマーシャリングコードは:
JAXBContext jc = JAXBContext.newInstance(ListBucketResult.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setEventHandler(new javax.xml.bind.helpers.DefaultValidationEventHandler());
JAXBElement element = (JAXBElement) unmarshaller.unmarshal (inputStream);
ListBucketResult customer = (ListBucketResult) element.getValue();
誰かが私が間違っていることを教えてもらえますか?