【问题标题】:How could i document java.util.Map using spring docs我如何使用 spring 文档记录 java.util.Map
【发布时间】:2018-05-04 05:08:22
【问题描述】:

假设我有下一堂课

public class MyDTO implements Serializable {
    private static final long serialVersionUID = 1L;

    private String id;
    private Map<String, String> names;

    // public Getters and Setters
}

当我使用下一个代码用 Spring 记录它时

private static FieldDescriptor[] myDTOFields() {
  return new FieldDescriptor[] { 
    fieldWithPath("id").description("id description"),
    fieldWithPath("names").description("Names description") };
}

它不起作用,我得到一个错误。

org.springframework.restdocs.sn-p.SnippetException: 以下 部分有效载荷没有记录:

{
  "names" : {
    "en" : "test"
  }
}

那么我如何用 spring 文档记录 java.util.Map 呢?

谢谢:)

【问题讨论】:

    标签: spring spring-mvc spring-boot spring-restdocs


    【解决方案1】:

    作为described in the documentation,您可以为此使用PayloadDocumentation.subsectionWithPath(“names”)。这意味着 REST Docs 将 names 及其包含的所有内容视为已记录在案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-10
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 2020-02-21
      • 2018-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多