use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-cloud-open-service-broker by spring-cloud.
the class CatalogControllerIntegrationTest method setUp.
@Before
public void setUp() {
this.mockMvc = MockMvcBuilders.standaloneSetup(controller).setMessageConverters(new MappingJackson2HttpMessageConverter()).build();
serviceDefinition = ServiceFixture.getSimpleService();
Catalog catalog = Catalog.builder().serviceDefinitions(serviceDefinition).build();
when(catalogService.getCatalog()).thenReturn(catalog);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project entando-core by entando.
the class AbstractControllerTest method createExceptionResolver.
protected ExceptionHandlerExceptionResolver createExceptionResolver() {
final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("rest/messages");
messageSource.setUseCodeAsDefaultMessage(true);
ExceptionHandlerExceptionResolver exceptionResolver = new ExceptionHandlerExceptionResolver() {
@Override
protected ServletInvocableHandlerMethod getExceptionHandlerMethod(HandlerMethod handlerMethod, Exception exception) {
Method method = new ExceptionHandlerMethodResolver(RestExceptionHandler.class).resolveMethod(exception);
RestExceptionHandler validationHandler = new RestExceptionHandler();
validationHandler.setMessageSource(messageSource);
return new ServletInvocableHandlerMethod(validationHandler, method);
}
};
exceptionResolver.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
exceptionResolver.afterPropertiesSet();
return exceptionResolver;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project sailfish-mfa by picos-io.
the class MfaWebMvcConfigurer method addReturnValueHandlers.
@Override
public void addReturnValueHandlers(final List<HandlerMethodReturnValueHandler> returnValueHandlers) {
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
returnValueHandlers.add(new RequestResponseBodyMethodProcessor(messageConverters));
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project open-kilda by telstra.
the class WebConfig method restTemplate.
/**
* Rest template for performing REST calls.
*/
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
RestTemplate restTemplate = builder.build();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
restTemplate.getMessageConverters().add(converter);
return restTemplate;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project topcom-cloud by 545314690.
the class MyWebAppConfigurer method extendMessageConverters.
/**
* 添加返回结果缩进支持,如果存在pretty参数,则返回结果添加缩进
* @param converters
*/
@Override
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.replaceAll(c -> {
if (c instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter(mapper) {
@Override
protected void writePrefix(JsonGenerator generator, Object object) throws IOException {
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
if (attributes != null && attributes instanceof ServletRequestAttributes) {
String attribute = ((ServletRequestAttributes) attributes).getRequest().getParameter("pretty");
if (attribute != null) {
generator.setPrettyPrinter(new DefaultPrettyPrinter());
}
}
super.writePrefix(generator, object);
}
};
return converter;
} else {
return c;
}
});
}
Aggregations