Consider this code:
Foo{ String prop1; String prop2 }
Bar{ String prop1; int prop2 }
@GetMapping("/getFoo")
public Mono<ResponseEntity<Foo>> getFoo() {
return Mono.just(new Bar("a", 1))
.map(f -> new ResponseEntity(f, HttpStatus.OK);
}
@Test
public void test() {
webTestClient.get()
.uri("/getFoo")
.exchange()
.expectBody(Foo.class)
.consumeWith(f -> { assertEquals("a", f.getProp1());});
}
The test works while I've never created the entity of type Foo. Java being strongly typed I would expect a cast error somewhere. I assume that Spring Web does introspection to avoid the error, but it surprises me. Is it really of feature of Spring Web ? Or do I miss something ?