Details

    • Type: Task Task
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Works as Designed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      I'm using RestTemplate, which uses under Jackson.
      Now i've issiue with deserialization one element Array.
      In Jackson 1.8.x fixed this issiue by http://jira.codehaus.org/browse/JACKSON-526.

      Could you add way to set Jackson features from RestTemplate?

      import org.codehaus.jackson.map.DeserializationConfig;
      import org.codehaus.jackson.map.ObjectMapper;
      
      // ...
      
      ObjectMapper mapper = new ObjectMapper();
      mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
      
      // ...
      

        Activity

        Hide
        Roy Clarkson added a comment -

        The MappingJacksonHttpMessageConverter actually includes a method for setting a customized ObjectMapper. See the setObjectMapper method for more details. So you can do something like the following. I haven't tested this scenario, so please confirm whether this solves your issue. Thanks!

        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);

        MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter();
        messageConverter.setObjectMapper(mapper);
        List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
        messageConverters.add(messageConverter);
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(messageConverters);
        SomeObject response = restTemplate.getForObject(url, SomeObject.class);

        Show
        Roy Clarkson added a comment - The MappingJacksonHttpMessageConverter actually includes a method for setting a customized ObjectMapper. See the setObjectMapper method for more details. So you can do something like the following. I haven't tested this scenario, so please confirm whether this solves your issue. Thanks! ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true); MappingJacksonHttpMessageConverter messageConverter = new MappingJacksonHttpMessageConverter(); messageConverter.setObjectMapper(mapper); List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>(); messageConverters.add(messageConverter); RestTemplate restTemplate = new RestTemplate(); restTemplate.setMessageConverters(messageConverters); SomeObject response = restTemplate.getForObject(url, SomeObject.class);
        Hide
        Lukasz Strzelecki added a comment -

        Thanks.
        I've tested with Jackson 1.8.3, and this kind of configuration works.

        Show
        Lukasz Strzelecki added a comment - Thanks. I've tested with Jackson 1.8.3, and this kind of configuration works.
        Hide
        Roy Clarkson added a comment -

        Great! Thanks for the feedback.

        Show
        Roy Clarkson added a comment - Great! Thanks for the feedback.

          People

          • Assignee:
            Roy Clarkson
            Reporter:
            Lukasz Strzelecki
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: