I need to consume a WebService that outputs XML. In code snippet below:
Question:
Following is my code :
@Rest(rootUrl = "http://my.root.url", converters ={SimpleXmlHttpMessageConverter.class })
public interface MyRestClient {
@Get("/path/to/restmethod/{day}")
MyResponse getResult(int day); <-------------- Returns null when return type is changed to String
}
I tried setting return type to String. But it returns null with this error: Failed to convert value of type 'null' to required type 'java.lang.String'
.
Alright found the answer myself. In addition to changing the return type to String, I also had to add StringHttpMessageConverter as a converter. Snippet below:
@Rest(rootUrl = "http://my.root.url", converters = { StringHttpMessageConverter.class, SimpleXmlHttpMessageConverter.class})
Note: The order of converters is important.