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