The error show up when My code like this:
@Test
public void getTemplateByIdTest() throws Exception {
client.get().uri("/template/getTemplate/7")
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
.expectBody(VtTemplateVO.class)
.returnResult();
}
When I change my code like this,it's ok!
@Test
public void getTemplateByIdTest() throws Exception {
client.get().uri("/template/getTemplate/7")
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON_UTF8)
.expectBody(String.class)
.returnResult();
}
Why when I use .expectBody(VtTemplateVO.class)
it will say org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/json;charset=UTF-8' not supported
Somebody knows? please help,thanks
I was also facing this issue caused by Jackson.There needs to be a default constructor for the VtTemplateVO.class with annotated properties. Ex. what I did-
@JsonCreator
public Comment(@JsonProperty("id")String id, @JsonProperty("text")String text, @JsonProperty("createdTime") LocalDate createdTime) {
this.id = id;
this.text = text;
this.createdTime = createdTime;
}
Hope it works for you as well. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With