Announcement Announcement Module
Collapse
No announcement yet.
RestTemplate Can Not Convert Generic Types Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Hi, there is a unresolved new request in jira.

    Comment

    Working...
    X