use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project ma-modules-public by infiniteautomation.
the class BaseFullStackRestTest method setupMvc.
/**
* @param controllers
*/
protected void setupMvc(Object... controllers) {
this.objectMapper = MangoRestSpringConfiguration.createNewObjectMapper();
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(this.objectMapper);
this.mockMvc = standaloneSetup(controllers).setMessageConverters(converter).build();
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project incubator-servicecomb-java-chassis by apache.
the class SpringMvcIntegrationTestBase method ableToPostObjectAsJsonWithRequestVariable.
@Test
public void ableToPostObjectAsJsonWithRequestVariable() {
Person input = new Person();
input.setName("world");
String result = restTemplate.postForObject(controllerUrl + "saysomething?prefix={prefix}", jsonRequest(input), String.class, "hello");
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);
input = new Person();
input.setName("中国");
result = restTemplate.postForObject(controllerUrl + "saysomething?prefix={prefix}", jsonRequest(input), String.class, "hello");
assertThat(result, is("hello 中国"));
restTemplate.setMessageConverters(convertersOld);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project incubator-servicecomb-java-chassis by apache.
the class SpringMvcIntegrationTestBase method postsEndWithPathParam.
@Test
public void postsEndWithPathParam() {
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);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project oncotree by cBioPortal.
the class TopBraidRepository method query.
private List<T> query(String query, ParameterizedTypeReference<List<T>> parameterizedType, boolean refreshSessionOnFailure) throws TopBraidException {
String sessionId = topBraidSessionConfiguration.getSessionId();
logger.debug("query() -- sessionId: " + sessionId);
RestTemplate restTemplate = new RestTemplate();
// the default supported types for MappingJackson2HttpMessageConverter are:
// application/json and application/*+json
// our response content type is application/sparql-results+json-simple
// NOTE: if the response content type was one of the default types we
// would not have to add the message converter to the rest template
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
messageConverter.setSupportedMediaTypes(Collections.singletonList(new MediaType("application", "sparql-results+json-simple")));
restTemplate.getMessageConverters().add(messageConverter);
// set our JSESSIONID cookie and our params
HttpHeaders headers = new HttpHeaders();
headers.add("Cookie", "JSESSIONID=" + sessionId);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
map.add("format", "json-simple");
map.add("query", query);
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
// See: http://stackoverflow.com/questions/21987295/using-spring-resttemplate-in-generic-method-with-generic-parameter
try {
ResponseEntity<List<T>> response = restTemplate.exchange(topBraidURL, HttpMethod.POST, request, parameterizedType);
logger.debug("query() -- response.getBody(): '" + response.getBody() + "'");
return response.getBody();
} catch (RestClientException e) {
logger.debug("query() -- caught RestClientException");
// see if we should try again, maybe the session expired
if (refreshSessionOnFailure == true) {
// force refresh of the session id
sessionId = topBraidSessionConfiguration.getFreshSessionId();
// do not make a second attempt
return query(query, parameterizedType, false);
}
throw new TopBraidException("Failed to connect to TopBraid", e);
}
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project group2-backend by it-kmitl-2018.
the class CustomConfiguration method configureMessageConverters.
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(new MappingJackson2HttpMessageConverter(Json.jsonMapper));
converters.add(new MappingJackson2XmlHttpMessageConverter(Xml.xmlMapper));
}
Aggregations