你将注解放置在错误的位置-注解必须在类上,而不是在字段上。即:
@JsonInclude(Include.NON_NULL) //or Include.NON_EMPTY, if that fits your use case public static class Request { // ...}如注释中所述,在2.x以下的版本中,此注释的语法为:
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) // or JsonSerialize.Inclusion.NON_EMPTY
另一种选择是ObjectMapper直接配置,只需调用 mapper.setSerializationInclusion(Include.NON_NULL);



