[ANDROID-45] JSON - one element array Created: 10/Jul/11  Updated: 30/Apr/12  Resolved: 12/Jul/11

Status: Closed
Project: Spring for Android
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Minor
Reporter: Lukasz Strzelecki Assignee: Roy Clarkson
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


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

// ...


 Comments   
Comment by Roy Clarkson [ 12/Jul/11 ]

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

Comment by Lukasz Strzelecki [ 12/Jul/11 ]

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

Comment by Roy Clarkson [ 12/Jul/11 ]

Great! Thanks for the feedback.

Generated at Fri Jun 05 01:00:15 UTC 2020 using Jira 8.5.4#805004-sha1:0444eab799707f9ad7b248d69f858774aadfd250.