use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageReaderArgumentResolverTests method missingContentType.
@Test
public void missingContentType() throws Exception {
ServerWebExchange exchange = post("/path").body("{\"bar\":\"BARBAR\",\"foo\":\"FOOFOO\"}").toExchange();
ResolvableType type = forClassWithGenerics(Mono.class, TestBean.class);
MethodParameter param = this.testMethod.arg(type);
Mono<Object> result = this.resolver.readBody(param, true, this.bindingContext, exchange);
StepVerifier.create(result).expectError(UnsupportedMediaTypeStatusException.class).verify();
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method jacksonTypeOfListElement.
// SPR-12811
@Test
public void jacksonTypeOfListElement() throws Exception {
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, ParentClass.class);
List<ParentClass> body = Arrays.asList(new Foo("foo"), new Bar("bar"));
this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON_UTF8, this.exchange.getResponse().getHeaders().getContentType());
assertResponseBody("[{\"type\":\"foo\",\"parentProperty\":\"foo\"}," + "{\"type\":\"bar\",\"parentProperty\":\"bar\"}]");
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method jacksonTypeWithSubTypeOfListElement.
// SPR-13318
@Test
public void jacksonTypeWithSubTypeOfListElement() throws Exception {
MethodParameter returnType = on(TestController.class).resolveReturnType(List.class, Identifiable.class);
List<SimpleBean> body = Arrays.asList(new SimpleBean(123L, "foo"), new SimpleBean(456L, "bar"));
this.resultHandler.writeBody(body, returnType, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON_UTF8, this.exchange.getResponse().getHeaders().getContentType());
assertResponseBody("[{\"id\":123,\"name\":\"foo\"},{\"id\":456,\"name\":\"bar\"}]");
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method jacksonTypeWithSubType.
// SPR-13318
@Test
public void jacksonTypeWithSubType() throws Exception {
SimpleBean body = new SimpleBean(123L, "foo");
MethodParameter type = on(TestController.class).resolveReturnType(Identifiable.class);
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
assertEquals(APPLICATION_JSON_UTF8, this.exchange.getResponse().getHeaders().getContentType());
assertResponseBody("{\"id\":123,\"name\":\"foo\"}");
}
use of org.springframework.core.MethodParameter in project spring-framework by spring-projects.
the class MessageWriterResultHandlerTests method useDefaultContentType.
// SPR-12894
@Test
public void useDefaultContentType() throws Exception {
Resource body = new ClassPathResource("logo.png", getClass());
MethodParameter type = on(TestController.class).resolveReturnType(Resource.class);
this.resultHandler.writeBody(body, type, this.exchange).block(Duration.ofSeconds(5));
assertEquals("image/x-png", this.exchange.getResponse().getHeaders().getFirst("Content-Type"));
}
Aggregations