Search in sources :

Example 96 with MappingJackson2HttpMessageConverter

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

the class OAuth2IntegrationTestSupport method getOAuth2RestTemplate.

protected OAuth2RestTemplate getOAuth2RestTemplate(final ClientCredentialsResourceDetails resourceDetails) {
    DefaultOAuth2ClientContext clientContext = new DefaultOAuth2ClientContext();
    OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(resourceDetails, clientContext);
    restTemplate.setMessageConverters(singletonList(new MappingJackson2HttpMessageConverter()));
    return restTemplate;
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) DefaultOAuth2ClientContext(org.springframework.security.oauth2.client.DefaultOAuth2ClientContext) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate)

Example 97 with MappingJackson2HttpMessageConverter

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

the class RestTemplateBasicLiveTest method givenFooService_whenPatchExistingEntity_thenItIsUpdated.

// PATCH
@Test
public void givenFooService_whenPatchExistingEntity_thenItIsUpdated() {
    final HttpHeaders headers = prepareBasicAuthHeaders();
    final HttpEntity<Foo> request = new HttpEntity<>(new Foo("bar"), headers);
    // Create Resource
    final ResponseEntity<Foo> createResponse = restTemplate.exchange(fooResourceUrl, HttpMethod.POST, request, Foo.class);
    // Update Resource
    final Foo updatedResource = new Foo("newName");
    updatedResource.setId(createResponse.getBody().getId());
    final String resourceUrl = fooResourceUrl + '/' + createResponse.getBody().getId();
    final HttpEntity<Foo> requestUpdate = new HttpEntity<>(updatedResource, headers);
    final ClientHttpRequestFactory requestFactory = getSimpleClientHttpRequestFactory();
    final RestTemplate template = new RestTemplate(requestFactory);
    template.setMessageConverters(Arrays.asList(new MappingJackson2HttpMessageConverter()));
    template.patchForObject(resourceUrl, requestUpdate, Void.class);
    // Check that Resource was updated
    final ResponseEntity<Foo> updateResponse = restTemplate.exchange(resourceUrl, HttpMethod.GET, new HttpEntity<>(headers), Foo.class);
    final Foo foo = updateResponse.getBody();
    assertThat(foo.getName(), is(updatedResource.getName()));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) HttpEntity(org.springframework.http.HttpEntity) Foo(org.baeldung.web.dto.Foo) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 98 with MappingJackson2HttpMessageConverter

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

the class WebConfig method configureMessageConverters.

// 
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> messageConverters) {
    final Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder();
    builder.indentOutput(true).dateFormat(new SimpleDateFormat("dd-MM-yyyy hh:mm"));
    messageConverters.add(new MappingJackson2HttpMessageConverter(builder.build()));
    messageConverters.add(new MappingJackson2XmlHttpMessageConverter(builder.createXmlMapper(true).build()));
    messageConverters.add(createXmlHttpMessageConverter());
    // messageConverters.add(new MappingJackson2HttpMessageConverter());
    messageConverters.add(new ProtobufHttpMessageConverter());
    messageConverters.add(new KryoHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    super.configureMessageConverters(messageConverters);
}
Also used : ProtobufHttpMessageConverter(org.springframework.http.converter.protobuf.ProtobufHttpMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) Jackson2ObjectMapperBuilder(org.springframework.http.converter.json.Jackson2ObjectMapperBuilder) KryoHttpMessageConverter(org.baeldung.config.converter.KryoHttpMessageConverter) MappingJackson2XmlHttpMessageConverter(org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter) SimpleDateFormat(java.text.SimpleDateFormat) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter)

Example 99 with MappingJackson2HttpMessageConverter

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

the class WebConfig method configureMessageConverters.

// beans
@Override
public void configureMessageConverters(final List<HttpMessageConverter<?>> converters) {
    super.configureMessageConverters(converters);
    converters.add(new MappingJackson2HttpMessageConverter());
}
Also used : MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)

Example 100 with MappingJackson2HttpMessageConverter

use of org.springframework.http.converter.json.MappingJackson2HttpMessageConverter in project ma-core-public by infiniteautomation.

the class MangoRestSpringConfiguration method configureMessageConverters.

/**
 * Configure the Message Converters for the API for now only JSON
 */
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
    converters.add(new ResourceHttpMessageConverter());
    converters.add(new MappingJackson2HttpMessageConverter(getObjectMapper()));
    converters.add(new CsvMessageConverter());
    converters.add(new CsvRowMessageConverter());
    converters.add(new CsvQueryArrayStreamMessageConverter());
    converters.add(new CsvDataPageQueryStreamMessageConverter());
    converters.add(new ByteArrayHttpMessageConverter());
    converters.add(new HtmlHttpMessageConverter());
    converters.add(new SerotoninJsonMessageConverter());
    converters.add(new ExceptionCsvMessageConverter());
    // Now is a good time to register our Sero Json Converter
    Common.JSON_CONTEXT.addConverter(new AbstractRestModelConverter(), AbstractRestModel.class);
}
Also used : CsvDataPageQueryStreamMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvDataPageQueryStreamMessageConverter) SerotoninJsonMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.SerotoninJsonMessageConverter) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) CsvQueryArrayStreamMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvQueryArrayStreamMessageConverter) CsvRowMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvRowMessageConverter) HtmlHttpMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.HtmlHttpMessageConverter) ResourceHttpMessageConverter(org.springframework.http.converter.ResourceHttpMessageConverter) ByteArrayHttpMessageConverter(org.springframework.http.converter.ByteArrayHttpMessageConverter) AbstractRestModelConverter(com.serotonin.m2m2.util.AbstractRestModelConverter) ExceptionCsvMessageConverter(com.infiniteautomation.mango.rest.v2.converters.ExceptionCsvMessageConverter) CsvMessageConverter(com.serotonin.m2m2.web.mvc.rest.v1.converters.CsvMessageConverter) ExceptionCsvMessageConverter(com.infiniteautomation.mango.rest.v2.converters.ExceptionCsvMessageConverter)

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