Search in sources :

Example 66 with MappingJackson2HttpMessageConverter

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;
        }
    }
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 67 with MappingJackson2HttpMessageConverter

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;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter)

Example 68 with MappingJackson2HttpMessageConverter

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;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jackson2ObjectMapperFactoryBean(org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean) SimpleDateFormat(java.text.SimpleDateFormat)

Example 69 with MappingJackson2HttpMessageConverter

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);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MediaType(org.springframework.http.MediaType) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 70 with MappingJackson2HttpMessageConverter

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());
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) MediaType(org.springframework.http.MediaType) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AllEncompassingFormHttpMessageConverter(org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Aggregations

MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)122 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)51 ArrayList (java.util.ArrayList)46 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)38 Test (org.junit.jupiter.api.Test)28 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)25 RestTemplate (org.springframework.web.client.RestTemplate)25 MappingJackson2XmlHttpMessageConverter (org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter)21 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)20 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)19 HandlerMethod (org.springframework.web.method.HandlerMethod)17 Method (java.lang.reflect.Method)16 Test (org.junit.Test)16 MethodParameter (org.springframework.core.MethodParameter)16 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)15 Bean (org.springframework.context.annotation.Bean)14 List (java.util.List)9 HttpEntity (org.springframework.http.HttpEntity)7 MediaType (org.springframework.http.MediaType)6 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)6