如何解决JsonIgnore 不适用于 Spring Rest-Docs
我已经创建了一个端点并为它实现了一个 rest-doc。 https://scacap.github.io/spring-auto-restdocs/
@PostMapping("post-item")
public ResponseEntity<?> postItem(@RequestBody ItemDto dto)
{
...
}
class ItemDto {
String value;
@JsonIgnore
public String getother() {
...
}
}
@BeforeEach
public void setUp(WebApplicationContext webApplicationContext,RestDocumentationContextProvider restDocumentation,@Autowired ObjectMapper objectMapper,@Value("${documentation.test.domain}") String domainName)
{
this.mockmvc = mockmvcBuilders.webAppContextSetup(webApplicationContext)
.alwaysDo(JacksonResultHandlers.prepareJackson(objectMapper))
.apply(documentationConfiguration(restDocumentation)
.uris()
.withScheme("http")
.withHost(domainName)
.withPort(8080)
.and().snippets()...
}
@Test
public void postItem() throws Exception
{
this.mockmvc.perform(post("/post-item")
.contentType(MediaType.APPLICATION_JSON)
.content(gson.toJson(new ItemDto("value"))))
.andExpect(status().isOk());
}
因此,spring rest-docs 生成带有 @JsonIgnore 字段的文档。
Request fields
value
other
有没有办法忽略 spring rest-docs 中的这个 @JsonIgnore 字段?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。