Search in sources :

Example 1 with Jackson2HalModule

use of org.springframework.hateoas.hal.Jackson2HalModule in project taskana by Taskana.

the class WorkbasketControllerIntTest method getRestTemplate.

/**
 * Return a REST template which is capable of dealing with responses in HAL format
 *
 * @return RestTemplate
 */
private RestTemplate getRestTemplate() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jackson2HalModule());
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    converter.setObjectMapper(mapper);
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
    return template;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule)

Example 2 with Jackson2HalModule

use of org.springframework.hateoas.hal.Jackson2HalModule in project taskana by Taskana.

the class TaskControllerIntTest method getRestTemplate.

/**
 * Return a REST template which is capable of dealing with responses in HAL format
 *
 * @return RestTemplate
 */
private RestTemplate getRestTemplate() {
    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new Jackson2HalModule());
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    converter.setObjectMapper(mapper);
    RestTemplate template = new RestTemplate(Collections.<HttpMessageConverter<?>>singletonList(converter));
    return template;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule)

Example 3 with Jackson2HalModule

use of org.springframework.hateoas.hal.Jackson2HalModule in project spring-cloud-microservice-example by kbastani.

the class Application method mappingJackson2HttpMessageConverter.

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
    MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
    jsonConverter.setSupportedMediaTypes(MediaType.parseMediaTypes("application/hal+json"));
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
    objectMapper.registerModule(new Jackson2HalModule());
    jsonConverter.setObjectMapper(objectMapper);
    return jsonConverter;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Jackson2HalModule(org.springframework.hateoas.hal.Jackson2HalModule) Bean(org.springframework.context.annotation.Bean)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Jackson2HalModule (org.springframework.hateoas.hal.Jackson2HalModule)3 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)3 RestTemplate (org.springframework.web.client.RestTemplate)2 Bean (org.springframework.context.annotation.Bean)1