use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project Gaffer by gchq.
the class RestTemplateProvider method createJsonMessageConverter.
private MappingJackson2HttpMessageConverter createJsonMessageConverter() {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
messageConverter.setObjectMapper(new ObjectMapperProvider().getObjectMapper());
return messageConverter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project java-chassis by ServiceComb.
the class SpringMvcIntegrationTestBase method postsEndWithPathParam.
@Test
public void postsEndWithPathParam() throws Exception {
String result = restTemplate.postForObject(controllerUrl + "sayhello/{name}", null, String.class, "world");
assertThat(jsonOf(result, String.class), is("hello world"));
List<HttpMessageConverter<?>> convertersOld = restTemplate.getMessageConverters();
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
restTemplate.setMessageConverters(converters);
result = restTemplate.postForObject(controllerUrl + "sayhello/{name}", null, String.class, "中 国");
assertThat(result, is("hello 中 国"));
restTemplate.setMessageConverters(convertersOld);
ListenableFuture<ResponseEntity<String>> listenableFuture = asyncRestTemplate.postForEntity(controllerUrl + "sayhello/{name}", null, String.class, "world");
ResponseEntity<String> futureResonse = listenableFuture.get();
assertThat(jsonOf(futureResonse.getBody(), String.class), is("hello world"));
asyncRestTemplate.setMessageConverters(converters);
listenableFuture = asyncRestTemplate.postForEntity(controllerUrl + "sayhello/{name}", null, String.class, "中 国");
futureResonse = listenableFuture.get();
assertThat(futureResonse.getBody(), is("hello 中 国"));
asyncRestTemplate.setMessageConverters(convertersOld);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-framework by spring-projects.
the class ServletAnnotationControllerHandlerMethodTests method httpEntityWithContentType.
// SPR-16172
@PathPatternsParameterizedTest
void httpEntityWithContentType(boolean usePathPatterns) throws Exception {
initDispatcherServlet(ResponseEntityController.class, usePathPatterns, wac -> {
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
messageConverters.add(new MappingJackson2HttpMessageConverter());
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
adapterDef.getPropertyValues().add("messageConverters", messageConverters);
wac.registerBeanDefinition("handlerAdapter", adapterDef);
});
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/test-entity");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader("Content-Type")).isEqualTo("application/xml");
assertThat(response.getContentAsString()).isEqualTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<testEntity><name>Foo Bar</name></testEntity>");
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-framework by spring-projects.
the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_CollectedValuesListWithResponseEntity.
// SPR-15478
@Test
public void wrapConcurrentResult_CollectedValuesListWithResponseEntity() throws Exception {
List<HttpMessageConverter<?>> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter());
ResolvableType elementType = ResolvableType.forClass(Bar.class);
ReactiveTypeHandler.CollectedValuesList result = new ReactiveTypeHandler.CollectedValuesList(elementType);
result.add(new Bar("foo"));
result.add(new Bar("bar"));
ContentNegotiationManager manager = new ContentNegotiationManager();
this.returnValueHandlers.addHandler(new RequestResponseBodyMethodProcessor(converters, manager));
ServletInvocableHandlerMethod hm = getHandlerMethod(new ResponseEntityHandler(), "handleFlux");
hm = hm.wrapConcurrentResult(result);
hm.invokeAndHandle(this.webRequest, this.mavContainer);
assertThat(this.response.getStatus()).isEqualTo(200);
assertThat(this.response.getContentAsString()).isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-framework by spring-projects.
the class ServletInvocableHandlerMethodTests method wrapConcurrentResult_CollectedValuesList.
@Test
public void wrapConcurrentResult_CollectedValuesList() throws Exception {
List<HttpMessageConverter<?>> converters = Collections.singletonList(new MappingJackson2HttpMessageConverter());
ResolvableType elementType = ResolvableType.forClass(List.class);
ReactiveTypeHandler.CollectedValuesList result = new ReactiveTypeHandler.CollectedValuesList(elementType);
result.add(Arrays.asList("foo1", "bar1"));
result.add(Arrays.asList("foo2", "bar2"));
ContentNegotiationManager manager = new ContentNegotiationManager();
this.returnValueHandlers.addHandler(new RequestResponseBodyMethodProcessor(converters, manager));
ServletInvocableHandlerMethod hm = getHandlerMethod(new MethodLevelResponseBodyHandler(), "handleFluxOfLists");
hm = hm.wrapConcurrentResult(result);
hm.invokeAndHandle(this.webRequest, this.mavContainer);
assertThat(this.response.getStatus()).isEqualTo(200);
assertThat(this.response.getContentAsString()).isEqualTo("[[\"foo1\",\"bar1\"],[\"foo2\",\"bar2\"]]");
}
Aggregations