Search in sources :

Example 21 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project spring-cloud-netflix by spring-cloud.

the class RestTemplateTransportClientFactory method mappingJacksonHttpMessageConverter.

/**
 * Provides the serialization configurations required by the Eureka Server. JSON
 * content exchanged with eureka requires a root node matching the entity being
 * serialized or deserialized. Achived with
 * {@link SerializationFeature.WRAP_ROOT_VALUE} and
 * {@link DeserializationFeature.UNWRAP_ROOT_VALUE}.
 * {@link PropertyNamingStrategy.SnakeCaseStrategy} is applied to the underlying
 * {@link ObjectMapper}.
 *
 * @return
 */
public MappingJackson2HttpMessageConverter mappingJacksonHttpMessageConverter() {
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setObjectMapper(new ObjectMapper().setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE));
    SimpleModule jsonModule = new SimpleModule();
    // keyFormatter, compact));
    jsonModule.setSerializerModifier(createJsonSerializerModifier());
    converter.getObjectMapper().registerModule(jsonModule);
    converter.getObjectMapper().configure(SerializationFeature.WRAP_ROOT_VALUE, true);
    converter.getObjectMapper().configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
    converter.getObjectMapper().addMixIn(Applications.class, ApplicationsJsonMixIn.class);
    converter.getObjectMapper().addMixIn(InstanceInfo.class, InstanceInfoJsonMixIn.class);
    return converter;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SimpleModule(com.fasterxml.jackson.databind.module.SimpleModule)

Example 22 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project nzbhydra2 by theotherp.

the class WebConfiguration method extendMessageConverters.

/**
 * Enable pretty printing of returned JSON
 */
@Override
protected void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
    for (HttpMessageConverter<?> converter : converters) {
        if (converter instanceof MappingJackson2HttpMessageConverter) {
            MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
            jacksonConverter.setPrettyPrint(true);
        }
    }
    converters.add(0, new NewznabAndTorznabResponseNamespaceFixer(marshaller()));
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 23 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project TranslateIt-api by zunpiau.

the class WebConfig method configureMessageConverters.

@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    ArrayList<MediaType> mediaTypes = new ArrayList<>(2);
    mediaTypes.add(new MediaType(MediaType.TEXT_PLAIN, StandardCharsets.UTF_8));
    mediaTypes.add(new MediaType(MediaType.TEXT_HTML, StandardCharsets.UTF_8));
    StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter(StandardCharsets.UTF_8);
    stringHttpMessageConverter.setSupportedMediaTypes(mediaTypes);
    MappingJackson2HttpMessageConverter jackson2HttpMessageConverter = new MappingJackson2HttpMessageConverter();
    jackson2HttpMessageConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
    converters.add(stringHttpMessageConverter);
    converters.add(jackson2HttpMessageConverter);
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) ArrayList(java.util.ArrayList) MediaType(org.springframework.http.MediaType) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 24 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project thingsboard by thingsboard.

the class AbstractControllerTest method json.

@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
    MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
    HttpMessageConverter converter = o instanceof String ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
    converter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
    return mockHttpOutputMessage.getBodyAsString();
}
Also used : MockHttpOutputMessage(org.springframework.mock.http.MockHttpOutputMessage) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 25 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project carina by qaprosoft.

the class RestTemplateBuilder method build.

public RestTemplate build() {
    if (!isUseDefaultJsonMessageConverter) {
        HttpMessageConverter<?> httpMessageConverter = Iterables.tryFind(restTemplate.getMessageConverters(), new Predicate<HttpMessageConverter<?>>() {

            @Override
            public boolean apply(HttpMessageConverter<?> input) {
                return input instanceof MappingJackson2HttpMessageConverter;
            }
        }).orNull();
        restTemplate.getMessageConverters().remove(httpMessageConverter);
    }
    restTemplate.getMessageConverters().addAll(httpMessageConverters);
    if (isDisableSslChecking) {
        restTemplate.setRequestFactory(new DisabledSslClientHttpRequestFactory());
    }
    if (isUseBasicAuth) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(basicAuthUsername, basicAuthPassword));
        HttpClient httpClient = HttpClients.custom().setDefaultCredentialsProvider(credentialsProvider).build();
        restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
    }
    return restTemplate;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) HttpClient(org.apache.http.client.HttpClient) AbstractHttpMessageConverter(org.springframework.http.converter.AbstractHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) DisabledSslClientHttpRequestFactory(com.qaprosoft.hockeyapp.http.resttemplate.ssl.DisabledSslClientHttpRequestFactory) Predicate(com.google.common.base.Predicate) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

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