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;
}
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()));
}
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);
}
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();
}
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;
}
Aggregations