Search in sources :

Example 1 with KryoHttpMessageConverter

use of org.baeldung.config.converter.KryoHttpMessageConverter in project tutorials by eugenp.

the class WebConfig method configureMessageConverters.

// 
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
    final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
    messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
    messageConverters.add(createXmlHttpMessageConverter());
    // messageConverters.add(new MappingJackson2HttpMessageConverter());
    messageConverters.add(new ProtobufHttpMessageConverter());
    messageConverters.add(new KryoHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    super.configureMessageConverters(messageConverters);
}
Also used : ProtobufHttpMessageConverter(org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) KryoHttpMessageConverter(org.baeldung.config.converter.KryoHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 2 with KryoHttpMessageConverter

use of org.baeldung.config.converter.KryoHttpMessageConverter in project tutorials by eugenp.

the class SpringHttpMessageConvertersLiveTest method givenConsumingKryo_whenReadingTheFoo_thenCorrect.

@Test
public void givenConsumingKryo_whenReadingTheFoo_thenCorrect() {
    final String URI = BASE_URI + "foos/{id}";
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(Arrays.asList(new KryoHttpMessageConverter()));
    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(KryoHttpMessageConverter.KRYO));
    final HttpEntity<String> entity = new HttpEntity<String>(headers);
    final ResponseEntity<Foo> response = restTemplate.exchange(URI, HttpMethod.GET, entity, Foo.class, "1");
    final Foo resource = response.getBody();
    assertThat(resource, notNullValue());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) KryoHttpMessageConverter(org.baeldung.config.converter.KryoHttpMessageConverter) Foo(org.baeldung.web.dto.Foo) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Aggregations

KryoHttpMessageConverter (org.baeldung.config.converter.KryoHttpMessageConverter)2 SimpleDateFormat (java.text.SimpleDateFormat)1 Foo (org.baeldung.web.dto.Foo)1 Test (org.junit.Test)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)1 Jackson2ObjectMapperBuilder (org.springframework.http.converter.json.Jackson2ObjectMapperBuilder)1 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)1 ProtobufHttpMessageConverter (org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter)1 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)1 RestTemplate (org.springframework.web.client.RestTemplate)1