generic type in @RequestBody
hello guys.
i have a problem with my communication between android app and java server using spring mobile on my phone and
spring mvc 3.
i want to transmit some generic data to the server and back.
after i send data from the client the app crashes with the exception 415: unsupported media type.
my server implementation looks like this:
Code:
@RequestMapping(value = "/restclient/dosomething", method = RequestMethod.POST)
public @ResponseBody Container<A, B, C> getRestTasks(@RequestBody Container<A, B, C> container){
//do something with container
return container;
}
my client looks like this:
Code:
public <T> T get(Class<T> gen, String url, Object obj) {
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
// Create a new RestTemplate instance
RestTemplate restTemplate = new RestTemplate();
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
ClientSessionHttpRequestInterceptor interceptor = new ClientSessionHttpRequestInterceptor();
interceptors.add(interceptor);
restTemplate.setInterceptors( interceptors);
restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
return gen.cast(restTemplate.postForObject(url, obj, gen));
}
the get Method is called like this:
Code:
Container<A, B, C> prototype = new Container<X, Y, Z>();
Container<X, Y, Z> container= get(Container.class, url, prototype);
X is subclass of A
Y is subclass of B
Z is subclass of C
i think during the serialization (MappingJacksonHttpMessageConverter) typeinformation get lost.
tracing the request with wireshark i found out that the type of X, Y, Z were set to object...
i have no idea to solve this problem...
i would appreciate any usefull ideas, and sorry for my english ;-)!
Thanks a lot,
zix