spring - 我如何使用 spring 文档记录 java.util.Map

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

想象我有下一个类

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.snippet.SnippetException: The following parts of the payload were not documented:

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


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

谢谢 :)

最佳答案

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

关于spring - 我如何使用 spring 文档记录 java.util.Map,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47401195/

相关文章:

java - 如何在 Spring 应用程序上下文中将 Class<?> 设置为属性值?

java - 在 Spring Security 中与 hasPermission 一起使用时,权限参数是否区分大小写?

java - 如何使用 postgresql 在 Spring boot 中的 addScaler() 方法中添加枚举值?

java - Hibernate JPA 和 Spring javax.persistence.TransactionRequiredException : no transaction is in progress (2)

java spring URL映射

Spring Boot REST API/Spring Security : Return custom message when authentication fails

java - 在Spring MVC中,为什么我的@RequestParam消失了?

java - 在我的 security-config.xml 中引用特定的密码编码器

java - 在 Spring Boot 中处理无效的 PathVariables

Java Spring Boot 访问 MariaDB 的 View ?