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;
}
}
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project ETSMobile-Android2 by ApplETS.
the class MyJackSpringAndroidSpiceService method createRestTemplate.
@Override
public RestTemplate createRestTemplate() {
RestTemplate restTemplate = new RestTemplate();
// Set Converters
final 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 geode by apache.
the class RestTestUtils method createMappingJackson2HttpMessageConverter.
public static HttpMessageConverter<Object> createMappingJackson2HttpMessageConverter() {
final Jackson2ObjectMapperFactoryBean objectMapperFactoryBean = new Jackson2ObjectMapperFactoryBean();
objectMapperFactoryBean.setFailOnEmptyBeans(true);
objectMapperFactoryBean.setIndentOutput(true);
objectMapperFactoryBean.setDateFormat(new SimpleDateFormat("MM/dd/yyyy"));
objectMapperFactoryBean.setFeaturesToDisable(com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
objectMapperFactoryBean.setFeaturesToEnable(com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_COMMENTS, com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_SINGLE_QUOTES, com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT);
objectMapperFactoryBean.afterPropertiesSet();
final MappingJackson2HttpMessageConverter httpMessageConverter = new MappingJackson2HttpMessageConverter();
httpMessageConverter.setObjectMapper(objectMapperFactoryBean.getObject());
return httpMessageConverter;
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project uPortal by Jasig.
the class GoogleCustomSearchServiceTest method setup.
@Before
public void setup() throws Exception {
// Add handling of text/javascript content type
final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
final List<MediaType> supportedMediaTypes = new LinkedList<MediaType>(converter.getSupportedMediaTypes());
final MediaType textJavascriptMediaType = new MediaType("text", "javascript", MappingJackson2HttpMessageConverter.DEFAULT_CHARSET);
supportedMediaTypes.add(textJavascriptMediaType);
converter.setSupportedMediaTypes(supportedMediaTypes);
restTemplate.getMessageConverters().add(converter);
this.googleSearchController.setRestOperations(restTemplate);
// Uncomment to make real requests
// restTemplate.setRequestFactory(new CommonsClientHttpRequestFactory());
when(clientHttpRequest.getHeaders()).thenReturn(requestHttpHeaders);
when(clientHttpRequest.execute()).thenReturn(clientHttpResponse);
when(clientHttpResponse.getStatusCode()).thenReturn(HttpStatus.OK);
when(clientHttpResponse.getHeaders()).thenReturn(responseHttpHeaders);
when(responseHttpHeaders.getContentType()).thenReturn(textJavascriptMediaType);
}
use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project littlefisher-system by littlefishercoder.
the class WebSpringMvcConfig method configureMessageConverters.
/**
* Description: 消息转换器配置
*
* @param converters converters
*/
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter jacksonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper om = jacksonConverter.getObjectMapper();
om.setDateFormat(new SimpleDateFormat(DateUtil.DATETIME_FORMAT_1));
om.setLocale(Locale.CHINA);
om.setTimeZone(TimeZone.getTimeZone("GMT+8"));
List<MediaType> mediaTypeList = Lists.newArrayList();
mediaTypeList.add(new MediaType(MediaType.APPLICATION_JSON, Charsets.UTF_8));
mediaTypeList.add(new MediaType(MediaType.TEXT_HTML, Charsets.UTF_8));
jacksonConverter.setSupportedMediaTypes(mediaTypeList);
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter(Charsets.UTF_8);
stringConverter.setWriteAcceptCharset(false);
// 保持以下顺序
// "application/json" "application/*+json"
converters.add(jacksonConverter);
// "application/xml" "text/xml" "application/*+xml"
converters.add(new Jaxb2RootElementHttpMessageConverter());
// "application/xml" "text/xml" "application/*+xml"
converters.add(new SourceHttpMessageConverter<>());
// "application/x-www-form-urlencoded" "multipart/form-data"
converters.add(new AllEncompassingFormHttpMessageConverter());
// "application/octet-stream" "*/*"
converters.add(new ByteArrayHttpMessageConverter());
// "text/plain" "*/*"
converters.add(stringConverter);
// "*/*"
converters.add(new ResourceHttpMessageConverter());
}
Aggregations