Add Encoder constructor to HttpMessageConverterView
This commit is contained in:
parent
b45a48d0fc
commit
505569c992
|
@ -25,7 +25,9 @@ import org.reactivestreams.Publisher;
|
|||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.reactive.CodecHttpMessageConverter;
|
||||
import org.springframework.http.converter.reactive.HttpMessageConverter;
|
||||
import org.springframework.http.server.reactive.ServerHttpResponse;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
@ -48,6 +50,19 @@ public class HttpMessageConverterView implements View {
|
|||
private final List<MediaType> mediaTypes;
|
||||
|
||||
|
||||
/**
|
||||
* Create a {@code View} with the given {@code Encoder}.
|
||||
* Internally this creates
|
||||
* {@link CodecHttpMessageConverter#CodecHttpMessageConverter(Encoder)
|
||||
* CodecHttpMessageConverter(Encoder)}.
|
||||
*/
|
||||
public HttpMessageConverterView(Encoder<?> encoder) {
|
||||
this(new CodecHttpMessageConverter<>(encoder));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a View that delegates to the given message converter.
|
||||
*/
|
||||
public HttpMessageConverterView(HttpMessageConverter<?> converter) {
|
||||
Assert.notNull(converter, "'converter' is required.");
|
||||
this.converter = converter;
|
||||
|
@ -55,6 +70,9 @@ public class HttpMessageConverterView implements View {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the configured message converter.
|
||||
*/
|
||||
public HttpMessageConverter<?> getConverter() {
|
||||
return this.converter;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ package org.springframework.web.reactive;
|
|||
|
||||
import java.net.URI;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -30,7 +29,6 @@ import reactor.core.util.SignalKind;
|
|||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.codec.support.StringDecoder;
|
||||
import org.springframework.core.codec.support.StringEncoder;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
|
@ -63,7 +61,9 @@ import org.springframework.web.server.handler.FilteringWebHandler;
|
|||
import org.springframework.web.server.session.WebSessionManager;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
|
|
|
@ -35,12 +35,9 @@ import org.springframework.core.codec.support.JacksonJsonEncoder;
|
|||
import org.springframework.core.codec.support.Jaxb2Encoder;
|
||||
import org.springframework.core.codec.support.Pojo;
|
||||
import org.springframework.core.codec.support.StringEncoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.reactive.CodecHttpMessageConverter;
|
||||
import org.springframework.http.converter.reactive.HttpMessageConverter;
|
||||
import org.springframework.http.server.reactive.MockServerHttpRequest;
|
||||
import org.springframework.http.server.reactive.MockServerHttpResponse;
|
||||
import org.springframework.ui.ExtendedModelMap;
|
||||
|
@ -74,8 +71,7 @@ public class HttpMessageConverterViewTests {
|
|||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
HttpMessageConverter<?> converter = new CodecHttpMessageConverter<>(new JacksonJsonEncoder());
|
||||
this.view = new HttpMessageConverterView(converter);
|
||||
this.view = new HttpMessageConverterView(new JacksonJsonEncoder());
|
||||
this.model = new ExtendedModelMap();
|
||||
this.result = new HandlerResult(new Object(), null, ResolvableType.NONE, model);
|
||||
}
|
||||
|
@ -127,8 +123,7 @@ public class HttpMessageConverterViewTests {
|
|||
|
||||
@Test
|
||||
public void extractObjectMultipleMatchesNotSupported() throws Exception {
|
||||
HttpMessageConverter<?> converter = new CodecHttpMessageConverter<>(new StringEncoder());
|
||||
HttpMessageConverterView view = new HttpMessageConverterView(converter);
|
||||
HttpMessageConverterView view = new HttpMessageConverterView(new StringEncoder());
|
||||
view.setModelKeys(new HashSet<>(Arrays.asList("foo1", "foo2")));
|
||||
this.model.addAttribute("foo1", "bar1");
|
||||
this.model.addAttribute("foo2", "bar2");
|
||||
|
@ -145,8 +140,7 @@ public class HttpMessageConverterViewTests {
|
|||
|
||||
@Test
|
||||
public void extractObjectNotSupported() throws Exception {
|
||||
HttpMessageConverter<?> converter = new CodecHttpMessageConverter<>(new Jaxb2Encoder());
|
||||
HttpMessageConverterView view = new HttpMessageConverterView(converter);
|
||||
HttpMessageConverterView view = new HttpMessageConverterView(new Jaxb2Encoder());
|
||||
view.setModelKeys(new HashSet<>(Collections.singletonList("foo1")));
|
||||
this.model.addAttribute("foo1", "bar1");
|
||||
|
||||
|
|
Loading…
Reference in New Issue