com.octo.android.robospice.Jackson2SpringAndroidSpiceService Maven / Gradle / Ivy
package com.octo.android.robospice;
import java.util.List;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import android.app.Application;
import com.octo.android.robospice.persistence.CacheManager;
import com.octo.android.robospice.persistence.exception.CacheCreationException;
import com.octo.android.robospice.persistence.springandroid.json.jackson2.Jackson2ObjectPersisterFactory;
/**
* A {@link SpringAndroidSpiceService} dedicated to json web services via
* Jackson. Provides caching.
* @author sni
*/
public class Jackson2SpringAndroidSpiceService extends SpringAndroidSpiceService {
@Override
public CacheManager createCacheManager(Application application) throws CacheCreationException {
CacheManager cacheManager = new CacheManager();
cacheManager.addPersister(new Jackson2ObjectPersisterFactory(application));
return cacheManager;
}
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// web services support json responses
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
final List> listHttpMessageConverters = restTemplate.getMessageConverters();
listHttpMessageConverters.add(jsonConverter);
restTemplate.setMessageConverters(listHttpMessageConverters);
return restTemplate;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy