use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project robospice by stephanenicolas.
the class Jackson2SpringAndroidSpiceService method createRestTemplate.
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// web services support json responses
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
final List<HttpMessageConverter<?>> listHttpMessageConverters = restTemplate.getMessageConverters();
listHttpMessageConverters.add(jsonConverter);
restTemplate.setMessageConverters(listHttpMessageConverters);
return restTemplate;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-boot by spring-projects.
the class HttpMessageConvertersTests method addBeforeExistingConverter.
@Test
public void addBeforeExistingConverter() {
MappingJackson2HttpMessageConverter converter1 = new MappingJackson2HttpMessageConverter();
MappingJackson2HttpMessageConverter converter2 = new MappingJackson2HttpMessageConverter();
HttpMessageConverters converters = new HttpMessageConverters(converter1, converter2);
assertThat(converters.getConverters().contains(converter1)).isTrue();
assertThat(converters.getConverters().contains(converter2)).isTrue();
List<MappingJackson2HttpMessageConverter> httpConverters = new ArrayList<>();
for (HttpMessageConverter<?> candidate : converters) {
if (candidate instanceof MappingJackson2HttpMessageConverter) {
httpConverters.add((MappingJackson2HttpMessageConverter) candidate);
}
}
// The existing converter is still there, but with a lower priority
assertThat(httpConverters).hasSize(3);
assertThat(httpConverters.indexOf(converter1)).isEqualTo(0);
assertThat(httpConverters.indexOf(converter2)).isEqualTo(1);
assertThat(converters.getConverters().indexOf(converter1)).isNotEqualTo(0);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method defaultCharset.
// SPR-13631
@Test
public void defaultCharset() throws Exception {
Method method = JacksonController.class.getMethod("defaultCharset");
HandlerMethod handlerMethod = new HandlerMethod(new JacksonController(), method);
MethodParameter methodReturnType = handlerMethod.getReturnType();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
Object returnValue = new JacksonController().defaultCharset();
processor.handleReturnValue(returnValue, methodReturnType, this.container, this.request);
assertEquals("UTF-8", this.servletResponse.getCharacterEncoding());
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-framework by spring-projects.
the class RequestMappingHandlerAdapterTests method jsonpResponseBodyAdvice.
@Test
public void jsonpResponseBodyAdvice() throws Exception {
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
this.handlerAdapter.setMessageConverters(converters);
this.webAppContext.registerSingleton("jsonpAdvice", JsonpAdvice.class);
this.webAppContext.refresh();
testJsonp("callback", true);
testJsonp("_callback", true);
testJsonp("_Call.bAcK", true);
testJsonp("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.", true);
testJsonp("<script>", false);
testJsonp("!foo!bar", false);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project Activiti by Activiti.
the class DispatcherServletConfiguration method configureMessageConverters.
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
addDefaultHttpMessageConverters(converters);
for (HttpMessageConverter<?> converter : converters) {
if (converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = (MappingJackson2HttpMessageConverter) converter;
jackson2HttpMessageConverter.setObjectMapper(objectMapper);
break;
}
}
}
Aggregations