Search in sources :

Example 6 with Jaxb2RootElementHttpMessageConverter

use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project spring-framework by spring-projects.

the class XpathRequestMatchersIntegrationTests method setup.

@BeforeEach
public void setup() {
    List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
    List<Person> performers = Arrays.asList(new Person("Vladimir Ashkenazy").setSomeBoolean(false), new Person("Yehudi Menuhin").setSomeBoolean(true));
    this.people = new PeopleWrapper(composers, performers);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new Jaxb2RootElementHttpMessageConverter());
    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);
    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Also used : Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) ArrayList(java.util.ArrayList) RestTemplate(org.springframework.web.client.RestTemplate) Person(org.springframework.test.web.Person) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with Jaxb2RootElementHttpMessageConverter

use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter 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)

Example 8 with Jaxb2RootElementHttpMessageConverter

use of org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter in project spring-framework by spring-projects.

the class XmlContentRequestMatchersIntegrationTests method setup.

@BeforeEach
public void setup() {
    List<Person> composers = Arrays.asList(new Person("Johann Sebastian Bach").setSomeDouble(21), new Person("Johannes Brahms").setSomeDouble(.0025), new Person("Edvard Grieg").setSomeDouble(1.6035), new Person("Robert Schumann").setSomeDouble(Double.NaN));
    this.people = new PeopleWrapper(composers);
    List<HttpMessageConverter<?>> converters = new ArrayList<>();
    converters.add(new Jaxb2RootElementHttpMessageConverter());
    this.restTemplate = new RestTemplate();
    this.restTemplate.setMessageConverters(converters);
    this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
}
Also used : Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) Jaxb2RootElementHttpMessageConverter(org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter) ArrayList(java.util.ArrayList) RestTemplate(org.springframework.web.client.RestTemplate) Person(org.springframework.test.web.Person) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Jaxb2RootElementHttpMessageConverter (org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter)8 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)5 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)5 ArrayList (java.util.ArrayList)4 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)4 ByteArrayHttpMessageConverter (org.springframework.http.converter.ByteArrayHttpMessageConverter)3 ResourceHttpMessageConverter (org.springframework.http.converter.ResourceHttpMessageConverter)3 AllEncompassingFormHttpMessageConverter (org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)2 GsonHttpMessageConverter (org.springframework.http.converter.json.GsonHttpMessageConverter)2 MarshallingHttpMessageConverter (org.springframework.http.converter.xml.MarshallingHttpMessageConverter)2 Person (org.springframework.test.web.Person)2 RestTemplate (org.springframework.web.client.RestTemplate)2 PathPatternsParameterizedTest (org.springframework.web.servlet.handler.PathPatternsParameterizedTest)2 MockHttpServletRequest (org.springframework.web.testfixture.servlet.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.web.testfixture.servlet.MockHttpServletResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Bean (org.springframework.context.annotation.Bean)1