Search in sources :

Example 1 with MappingJacksonHttpMessageConverter

use of org.springframework.http.converter.json.MappingJacksonHttpMessageConverter in project robospice by stephanenicolas.

the class JacksonSpringAndroidSpiceService method createRestTemplate.

@Override
public RestTemplate createRestTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    // web services support json responses
    MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter();
    final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters();
    listHttpMessageConverters.add(jsonConverter);
    restTemplate.setMessageConverters(listHttpMessageConverters);
    return restTemplate;
}
Also used : MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter)

Example 2 with MappingJacksonHttpMessageConverter

use of org.springframework.http.converter.json.MappingJacksonHttpMessageConverter in project spring-data-document-examples by spring-projects.

the class RestTemplateActivity method onCreate.

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    TextView view = new TextView(this);
    view.append("Running tests...\n\n");
    setContentView(view);
    try {
        List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
        converters.add(new MappingJacksonHttpMessageConverter());
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setMessageConverters(converters);
        Map response = restTemplate.getForObject("http://127.0.0.1:5984", Map.class);
        view.append(response.toString());
        /*
			URL url = new URL("http:/127.0.0.1:5984");
			HttpURLConnection conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod("GET");
			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String line;
			List<String> lines= new ArrayList<String>();
			while((line = reader.readLine()) != null){
			    lines.add(line);
			}
			reader.close();
			view.append(lines.toString());*/
        view.append("all ok!");
    } catch (Exception e) {
        view.append(e.toString());
        Log.e("rest-template", "this is bad", e);
    }
}
Also used : MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) ArrayList(java.util.ArrayList) MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) TextView(android.widget.TextView) Map(java.util.Map)

Example 3 with MappingJacksonHttpMessageConverter

use of org.springframework.http.converter.json.MappingJacksonHttpMessageConverter in project spring-data-document-examples by spring-projects.

the class CouchDbConfig method restTemplate.

@Bean
public RestTemplate restTemplate() {
    RestTemplate restTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
    //converters.add(new MappingJacksonHttpMessageConverter());
    converters.add(new CouchDbMappingJacksonHttpMessageConverter());
    restTemplate.setMessageConverters(converters);
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) ArrayList(java.util.ArrayList) MappingJacksonHttpMessageConverter(org.springframework.http.converter.json.MappingJacksonHttpMessageConverter) CouchDbMappingJacksonHttpMessageConverter(com.springone.myrestaurants.web.CouchDbMappingJacksonHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) CouchDbMappingJacksonHttpMessageConverter(com.springone.myrestaurants.web.CouchDbMappingJacksonHttpMessageConverter) Bean(org.springframework.context.annotation.Bean)

Aggregations

HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)3 MappingJacksonHttpMessageConverter (org.springframework.http.converter.json.MappingJacksonHttpMessageConverter)3 RestTemplate (org.springframework.web.client.RestTemplate)3 ArrayList (java.util.ArrayList)2 TextView (android.widget.TextView)1 CouchDbMappingJacksonHttpMessageConverter (com.springone.myrestaurants.web.CouchDbMappingJacksonHttpMessageConverter)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1