use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method addDefaultHttpMessageConverters.
/**
* Adds a set of default HttpMessageConverter instances to the given list.
* Subclasses can call this method from {@link #configureMessageConverters(List)}.
* @param messageConverters the list to add the default message converters to
*/
protected final void addDefaultHttpMessageConverters(List<HttpMessageConverter<?>> messageConverters) {
StringHttpMessageConverter stringConverter = new StringHttpMessageConverter();
stringConverter.setWriteAcceptCharset(false);
messageConverters.add(new ByteArrayHttpMessageConverter());
messageConverters.add(stringConverter);
messageConverters.add(new ResourceHttpMessageConverter());
messageConverters.add(new SourceHttpMessageConverter<>());
messageConverters.add(new AllEncompassingFormHttpMessageConverter());
if (romePresent) {
messageConverters.add(new AtomFeedHttpMessageConverter());
messageConverters.add(new RssChannelHttpMessageConverter());
}
if (jackson2XmlPresent) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.xml().applicationContext(this.applicationContext).build();
messageConverters.add(new MappingJackson2XmlHttpMessageConverter(objectMapper));
} else if (jaxb2Present) {
messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
}
if (jackson2Present) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.json().applicationContext(this.applicationContext).build();
messageConverters.add(new MappingJackson2HttpMessageConverter(objectMapper));
} else if (gsonPresent) {
messageConverters.add(new GsonHttpMessageConverter());
}
if (jackson2SmilePresent) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.smile().applicationContext(this.applicationContext).build();
messageConverters.add(new MappingJackson2SmileHttpMessageConverter(objectMapper));
}
if (jackson2CborPresent) {
ObjectMapper objectMapper = Jackson2ObjectMapperBuilder.cbor().applicationContext(this.applicationContext).build();
messageConverters.add(new MappingJackson2CborHttpMessageConverter(objectMapper));
}
}
use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.
the class RequestPartIntegrationTests method setup.
@Before
public void setup() {
ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
converters.add(emptyBodyConverter);
converters.add(new ByteArrayHttpMessageConverter());
converters.add(new ResourceHttpMessageConverter());
converters.add(new MappingJackson2HttpMessageConverter());
AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
converter.setPartConverters(converters);
restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
restTemplate.setMessageConverters(Collections.singletonList(converter));
}
use of org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter in project spring-framework by spring-projects.
the class RequestResponseBodyMethodProcessorTests method resolveArgumentRawTypeFromParameterizedType.
@Test
public void resolveArgumentRawTypeFromParameterizedType() throws Exception {
String content = "fruit=apple&vegetable=kale";
this.servletRequest.setMethod("GET");
this.servletRequest.setContent(content.getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new AllEncompassingFormHttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
@SuppressWarnings("unchecked") MultiValueMap<String, String> result = (MultiValueMap<String, String>) processor.resolveArgument(paramMultiValueMap, container, request, factory);
assertNotNull(result);
assertEquals("apple", result.getFirst("fruit"));
assertEquals("kale", result.getFirst("vegetable"));
}
Aggregations