我试图在SpringBoot2中使用WebClient,如下所示:
client = WebClient.builder()
.baseUrl(host)
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
String reply = client.post().uri(URI.create(host + "/product/update")).body(BodyInserters.fromObject(product)).exchange().block().bodyToMono(String.class).block();
“产品”中的某些字段为空,例如“名称”字段。我得到这个错误:
org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field \"name\" (Class Product), not marked as ignorable\n at [Source: org.apache.catalina.connector.CoyoteInputStream@17a5cdd2; line: 1, column: 160] (through reference chain: Product[\"name\"])]\r\n"
如何告诉BodyInserter忽略空字段(如果有)?