Imagine I have next class
public class MyDTO implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private Map<String, String> names;
// public Getters and Setters
}
When I use the next code to document it with Spring
private static FieldDescriptor[] myDTOFields() {
return new FieldDescriptor[] {
fieldWithPath("id").description("id description"),
fieldWithPath("names").description("Names description") };
}
It doesn't work and I get an error.
org.springframework.restdocs.snippet.SnippetException: The following parts of the payload were not documented:
{ "names" : { "en" : "test" } }
So how could I document java.util.Map with spring docs?
Thanks :)
As described in the documentation, you could use PayloadDocumentation.subsectionWithPath(“names”)
for this. It will mean that REST Docs considers names
and everything that it contains as having been documented.