MessageConverters -> HttpMessageConverters

pull/165/head
Dave Syer 11 years ago
parent 370501f4a9
commit c78973e375

@ -88,9 +88,9 @@ modules when you add new features to your application.
Finally, if you provide any `@Beans` of type
`MappingJackson2HttpMessageConverter` then they will replace the
default value in the MVC configuration. Also, a convenience bean is
provided of type `MessageConverters` (always available if you use the
default MVC configuration) which has some useful methods to access the
default and user-enhanced message converters.
provided of type `HttpMessageConverters` (always available if you use
the default MVC configuration) which has some useful methods to access
the default and user-enhanced message converters.
See also the [section on `HttpMessageConverters`](#message.converters)
and the `WebMvcAutoConfiguration` source code for more details.
@ -104,7 +104,7 @@ converters by simply adding beans of that type in a Spring Boot
context. If a bean you add is of a type that would have been included
by default anyway (like `MappingJackson2HttpMessageConverter` for JSON
conversions) then it will replace the default value. A convenience
bean is provided of type `MessageConverters` (always available if you
bean is provided of type `HttpMessageConverters` (always available if you
use the default MVC configuration) which has some useful methods to
access the default and user-enhanced message converters (useful, for
example if you want to manually inject them into a custom

@ -40,7 +40,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.autoconfigure.web.DispatcherServletAutoConfiguration;
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration;
import org.springframework.boot.autoconfigure.web.MessageConverters;
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext;
@ -94,7 +94,7 @@ public class EndpointWebMvcAutoConfiguration implements ApplicationContextAware,
@Bean
@ConditionalOnMissingBean
public EndpointHandlerAdapter endpointHandlerAdapter(
final MessageConverters messageConverters) {
final HttpMessageConverters messageConverters) {
EndpointHandlerAdapter adapter = new EndpointHandlerAdapter();
adapter.setMessageConverters(messageConverters.getMessageConverters());
return adapter;

@ -33,7 +33,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupp
*
* @author Dave Syer
*/
public class MessageConverters {
public class HttpMessageConverters {
private List<HttpMessageConverter<?>> defaults;
@ -43,11 +43,11 @@ public class MessageConverters {
private List<HttpMessageConverter<?>> converters;
public MessageConverters() {
public HttpMessageConverters() {
this(Collections.<HttpMessageConverter<?>> emptyList());
}
public MessageConverters(Collection<HttpMessageConverter<?>> overrides) {
public HttpMessageConverters(Collection<HttpMessageConverter<?>> overrides) {
this.overrides = new ArrayList<HttpMessageConverter<?>>(overrides);
}

@ -116,10 +116,10 @@ public class WebMvcAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public MessageConverters messageConverters() {
public HttpMessageConverters messageConverters() {
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>(
this.converters);
return new MessageConverters(converters);
return new HttpMessageConverters(converters);
}
@Bean
@ -148,7 +148,7 @@ public class WebMvcAutoConfiguration {
private ResourceLoader resourceLoader;
@Autowired
private MessageConverters messageConverters;
private HttpMessageConverters messageConverters;
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {

@ -30,18 +30,18 @@ import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
*/
public class MessageConvertersTests {
public class HttpMessageConvertersTests {
@Test
public void defaultsCreated() {
MessageConverters messageConverters = new MessageConverters();
HttpMessageConverters messageConverters = new HttpMessageConverters();
assertFalse(messageConverters.getDefaultMessageConverters().isEmpty());
}
@Test
public void overrideExistingConverter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
MessageConverters messageConverters = new MessageConverters(
HttpMessageConverters messageConverters = new HttpMessageConverters(
Arrays.<HttpMessageConverter<?>> asList(converter));
assertTrue(messageConverters.getMessageConverters().contains(converter));
}
@ -49,7 +49,7 @@ public class MessageConvertersTests {
@Test
public void addNewOne() {
HttpMessageConverter<?> converter = Mockito.mock(HttpMessageConverter.class);
MessageConverters messageConverters = new MessageConverters(
HttpMessageConverters messageConverters = new HttpMessageConverters(
Arrays.<HttpMessageConverter<?>> asList(converter));
assertTrue(messageConverters.getMessageConverters().contains(converter));
assertEquals(converter, messageConverters.getMessageConverters().get(0));

@ -153,7 +153,7 @@ public class WebMvcAutoConfigurationTests {
.getBean(MappingJackson2HttpMessageConverter.class);
assertEquals(this.context.getBean(ObjectMapper.class),
converter.getObjectMapper());
MessageConverters converters = this.context.getBean(MessageConverters.class);
HttpMessageConverters converters = this.context.getBean(HttpMessageConverters.class);
assertTrue(converters.getMessageConverters().contains(converter));
assertEquals(converters.getMessageConverters(),
this.context.getBean(RequestMappingHandlerAdapter.class)

Loading…
Cancel
Save