我正在使用 spring 的 resttemplate 来调用 rest api 获取错误以解组 xml 以对象我的代码是:-
String uri = "http://devd.webservice.com/devpl/api/1.0/credential?apiKey=" + apiKey + "&signature=" + signature + "&timeStamp=" + timeStamp;
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.set("accountName", accountName);
requestHeaders.set("containerName", containerName);
requestHeaders.set("folderPath", folderPath);
requestHeaders.set("Content-Type","application/xml");
requestHeaders.set("Accept","application/xml");
RestTemplate template = getRestTemplate();
HttpEntity<String> requestEntity = new HttpEntity<String>(requestHeaders);
Credential result =(Credential)template.postForObject(uri,requestEntity,Credential.class);
我使用对象的对象类 bean:-
package com.simplidrivechn.netmagicsolutions.bean;
import com.thoughtworks.xstream.annotations.*;
@XStreamAlias("credential")
public class Credential
{
private String DestinationUrl;
private String AuthToken;
private String StorageUrl;
public String getAuthToken() {
return AuthToken;
}
public void setAuthToken(String AuthToken) {
this.AuthToken = AuthToken;
}
public String getDestinationUrl() {
return DestinationUrl;
}
public void setDestinationUrl(String DestinationUrl) {
this.DestinationUrl = DestinationUrl;
}
public String getStorageUrl() {
return StorageUrl;
}
public void setStorageUrl(String StorageUrl) {
this.StorageUrl = StorageUrl;
}
}
我的弹簧配置文件: -
<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
<property name="messageConverters">
<list>
<bean id="messageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
<property name="marshaller" ref="xstreamMarshaller" />
<property name="unmarshaller" ref="xstreamMarshaller" />
</bean>
</list>
</property>
</bean>
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">
<property name="aliases">
<props>
<prop key="credential">com.simplidrivechn.netmagicsolutions.bean.Credential</prop>
</props>
</property>
</bean>
</beans>
我收到错误:-
Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read [class com.simplidrivechn.netmagicsolutions.bean.Credential]; nested exception is org.springframework.oxm.UnmarshallingFailureException: XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.mapper.CannotResolveClassException: Credential : Credential
请帮我解决这个错误