Results 1 to 2 of 2

Thread: RestTemplate Can Not Convert Generic Types

  1. #1
    Join Date
    Sep 2011
    Posts
    2

    Default RestTemplate Can Not Convert Generic Types

    I have a model like that:

    Code:
    public class Wrapper<T> {
    
     private String message;
     private T data;
    
     public String getMessage() {
        return message;
     }
    
     public void setMessage(String message) {
        this.message = message;
     }
    
     public T getData() {
        return data;
     }
    
     public void setData(T data) {
        this.data = data;
     }
    
    }
    and I use resttemplate as follows:

    Code:
    ...
    Wrapper<Model> response = restTemplate.getForObject(URL, Wrapper.class, myMap);
    Model model = response.getData();
    ...
    However it throws a:

    Code:
    ClassCastException
    I think resttemplate can not understand my generic variable and maybe it accepts it as an Object instead of generic T. So it becomes a LinkedHashMap. You can read from it at here It says that when explaining from what it marshalls to:

    JSON Type | Java Type

    object | LinkedHashMap

    PS: I have a question here: http://stackoverflow.com/questions/8...g-resttemplate

  2. #2
    Join Date
    May 2011
    Location
    Madrid (Spain)
    Posts
    101

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •