Swagger 2不显示地图模型

时间:2016-12-19 10:35:35

标签: rest spring-mvc swagger swagger-ui swagger-2.0

我在Spring MVC应用程序上配置了springfox,并暴露了休息服务。  其中一个公开的服务将地图作为Requestbody参数:

@RequestMapping(value = "/uploadFiles", method = RequestMethod.POST, produces= "application/json", headers = "Accept=application/json")
    @ResponseBody
    public ResponseEntity<String> uploadFilesToGED(@RequestParam(value = "userId") String userId, @RequestBody Map<String,DocumentMetaData> documents  ) {
        GEDService.pushDocument(userId, documents);
        return new ResponseEntity<>(HttpStatus.ACCEPTED);
    }

问题在于,swagger-ui并没有向我显示map属性的空白模型,只显示了一对空括号{}。  我本来期望模型向我展示一个带有String的默认地图表示和对象DocumentMetaData的模型(其中包含自己的其他地图和列表......):

所以经过一段时间的谷歌搜索后,我发现了一些关于ObjectMapper配置的帖子。  我很简单:

public class RestAPIConfig extends WebMvcConfigurerAdapter {
...
        /**
     * configureMessageConverters
     */
    @Override
    public void configureMessageConverters(
            List<HttpMessageConverter<?>> converters) {
        converters.add(jackson2Converter());
        converters.add(new ByteArrayHttpMessageConverter());
        converters.add(new ResourceHttpMessageConverter());
        converters.add(new SourceHttpMessageConverter<Source>());
        converters.add(new AllEncompassingFormHttpMessageConverter());
        converters.add(new ObjectHttpMessageConverter());
           }

        /**
     * MappingJackson2HttpMessageConverter
     * 
     * @return Converter from java to json
     */
    @Bean
    public MappingJackson2HttpMessageConverter jackson2Converter() {
        MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
        converter.setObjectMapper(objectMapper());
        return converter;
    }

    /**
     * Object mapper
     * 
     * @return objectMapper
     */
    @Bean
    @Primary
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
        return objectMapper;
    }
...
}

为什么我会看到空括号而不是地图的空白表示?

THX

0 个答案:

没有答案