Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-7002

RestTemplate fails to convert properly for Generic Type Container with MappingJacksonHttpMessageConverter

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 3.0 GA, 3.0.1
    • Fix Version/s: 3.0.2
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      When I used RestTemplate to retrieve the result in Generic Type Container, the MappingJacksonHttpMessageConverter could not properly determine the type (due to erasure)

      e.g.

      List<MyDomain> myDomainList = restTemplate.getForObject(uri, List.class);
      will throw ClassCastException

      the MappingJacksonHttpMessageConverter could not determine that the List container should stores MyDomain objects by passing the List.class, it could only stores as List<LinkedHashedMap>

      Recommend to add something similar to TypeReference in Jackson. http://wiki.fasterxml.com/JacksonInFiveMinutes (Section: Data Binding with Generics) to solve this issue.

      Personal speaking, if the new HttpEntity could provide a setTypeReference() would be much convenient.
      e.g.
      HttpEntity httpEntity = new HttpEntity();
      httpEntity.setTypeReference(new TypeReference<List<MyDomain>>() {});

      List<MyDomain> myDomainList = restTemplate.getForObject(uri, httpEntity);

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                arjen.poutsma Arjen Poutsma
                Reporter:
                simonwg Simon Wong
                Last updater:
                Spring Issuemaster
              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  40 weeks, 1 day ago

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0d
                  0d
                  Logged:
                  Time Spent - 1.1h
                  1.1h