I am trying to parse the result from a RESTFull call using RestTemplate after this example http://thekspace.com/home/component/content/article/57-restful-clients-in-spring-3.html
The XML response looks something like this:
<brands>
<brand>
<nodeRef>1111111</nodeRef>
<name>Test</name>
</brand>
</brands>
First, I configured my application-context.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<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="brand">com.kipcast.dataModel.drugs.bean.BrandViewList</prop>
</props>
</property>
</bean>
</beans>
The com.kipcast.dataModel.drugs.bean.BrandViewList class is a bean with the definition of @XStreamAlias ("brand").
Here is how I do the rest:
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml", WebscriptCaller.class);
RestTemplate restTemplate = applicationContext.getBean("restTemplate", RestTemplate.class);
String url = "http://localhost:8081/alfresco/service/search/brand.xml?q={keyword}&alf_ticket={ticket}";
List<BrandViewList> results = (List<BrandViewList>) restTemplate.getForObject(url, List.class, params);
WebscriptCaller.class is the class from which I execute these instructions.
When I try to execute this, getForObject () fails, and I get this exception:
XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.mapper.CannotResolveClassException: brands
My question is: how can I fix this? Why am I getting such an exception? How can I tell him to skip the root tag?
-------------- --------------
, :
List<Brand> brandViewList = (List<Brand>) restTemplate.getForObject(url, Brand.class, params);
:
org.springframework.http.converter.HttpMessageNotReadableException: Could not read [class com.kipcast.dataModel.drugs.bean.Brand]; nested exception is org.springframework.oxm.UnmarshallingFailureException: XStream unmarshalling exception; nested exception is com.thoughtworks.xstream.converters.ConversionException: nodeRef : nodeRef
---- Debugging information ----
message : nodeRef
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : nodeRef
class : java.util.ArrayList
required-type : java.util.ArrayList
converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter
path : /brands/brand/nodeRef
line number : 3
class[1] : com.kipcast.dataModel.drugs.bean.Brands
converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
version : null
-------------------------------