<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=kamaci" rel="nofollow">Furkan KAMACI</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-8840?redirect=false" rel="nofollow">SPR-8840</a></strong> and commented</p>
<p dir="auto">I have a model like that:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="public class Wrapper&lt;T&gt; {

 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;
 }

}"><pre class="notranslate"><span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">Wrapper</span>&lt;<span class="pl-smi">T</span>&gt; {

 <span class="pl-k">private</span> <span class="pl-smi">String</span> <span class="pl-s1">message</span>;
 <span class="pl-k">private</span> <span class="pl-smi">T</span> <span class="pl-s1">data</span>;

 <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getMessage</span>() {
    <span class="pl-k">return</span> <span class="pl-s1">message</span>;
 }

 <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">setMessage</span>(<span class="pl-smi">String</span> <span class="pl-s1">message</span>) {
    <span class="pl-smi">this</span>.<span class="pl-s1">message</span> = <span class="pl-s1">message</span>;
 }

 <span class="pl-k">public</span> <span class="pl-smi">T</span> <span class="pl-en">getData</span>() {
    <span class="pl-k">return</span> <span class="pl-s1">data</span>;
 }

 <span class="pl-k">public</span> <span class="pl-smi">void</span> <span class="pl-en">setData</span>(<span class="pl-smi">T</span> <span class="pl-s1">data</span>) {
    <span class="pl-smi">this</span>.<span class="pl-s1">data</span> = <span class="pl-s1">data</span>;
 }

}</pre></div>
<p dir="auto">and I use resttemplate as follows:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="...
Wrapper&lt;Model&gt; response = restTemplate.getForObject(URL, Wrapper.class, myMap);
Model model = response.getData();
..."><pre class="notranslate">...
<span class="pl-smi">Wrapper</span>&lt;<span class="pl-smi">Model</span>&gt; <span class="pl-s1">response</span> = <span class="pl-s1">restTemplate</span>.<span class="pl-en">getForObject</span>(<span class="pl-c1">URL</span>, <span class="pl-smi">Wrapper</span>.<span class="pl-k">class</span>, <span class="pl-s1">myMap</span>);
<span class="pl-smi">Model</span> <span class="pl-s1">model</span> = <span class="pl-s1">response</span>.<span class="pl-en">getData</span>();
...</pre></div>
<p dir="auto">However it throws a:</p>
<p dir="auto">ClassCastException</p>
<p dir="auto">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.</p>
<hr>
<p dir="auto"><strong>Reference URL:</strong> <a href="http://forum.springsource.org/showthread.php?117511-RestTemplate-Can-Not-Convert-Generic-Types&amp;p=387485#post387485" rel="nofollow">http://forum.springsource.org/showthread.php?117511-RestTemplate-Can-Not-Convert-Generic-Types&amp;p=387485#post387485</a></p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398104042" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11685" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11685/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11685">#11685</a> Proper handling of parameterized types in RestTemplate (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=arjen.poutsma" rel="nofollow">Arjen Poutsma</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-7023?redirect=false" rel="nofollow">SPR-7023</a></strong> and commented</p>
<p dir="auto">Currently, the RestTemplate has no way to handle generic types. In other words, the following does not work:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="List&lt;MyDomain&gt; myDomainList = restTemplate.getForObject(uri, List.class);"><pre class="notranslate"><code class="notranslate">List&lt;MyDomain&gt; myDomainList = restTemplate.getForObject(uri, List.class);
</code></pre></div>
<p dir="auto">This should be fixed.</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 3.1.1</p>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398115515" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13482" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13482/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13482">#13482</a> RestTemplate Converting Generic Types (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398112570" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/13028" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/13028/hovercard" href="https://github.com/spring-projects/spring-framework/issues/13028">#13028</a> HttpMessageConverter doesn't support typed collections</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398199842" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/19423" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/19423/hovercard" href="https://github.com/spring-projects/spring-framework/issues/19423">#19423</a> Add PATCH HTTP operation to RestTemplate</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398103919" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/11667" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/11667/hovercard" href="https://github.com/spring-projects/spring-framework/issues/11667">#11667</a> RestTemplate fails to convert properly for Generic Type Container with MappingJacksonHttpMessageConverter</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/ed3823b045fd19cdb801609eb034c93dd4d75c3f/hovercard" href="https://github.com/spring-projects/spring-framework/commit/ed3823b045fd19cdb801609eb034c93dd4d75c3f"><tt>ed3823b</tt></a></p>
<p dir="auto">14 votes, 16 watchers</p>