Tag: 春季开机

springfox(swagger2)不能使用GsonHttpMessageConverterConfig

我正在尝试构建的是Spring-Boot(v1.2.3)应用程序,并将Rest API与SpringFox(swagger2)v2.0.0 我的Swagger弹簧配置 @EnableSwagger2 @Configuration public class SwaggerConfig { @Bean public Docket myApi() { return new Docket(DocumentationType.SWAGGER_2) .genericModelSubstitutes(DeferredResult.class) .useDefaultResponseMessages(false) .forCodeGeneration(false) .pathMapping(“/my-prj”); } } 我需要使用gson把我的pojo转换成json,我这样做: @Configuration public class GsonHttpMessageConverterConfig { @Bean public GsonHttpMessageConverter gsonHttpMessageConverter(Gson gson) { GsonHttpMessageConverter converter = new GsonHttpMessageConverter(); converter.setGson(gson); return converter; } } 麻烦的是,如果使用GsonHttpMessageConverter ,swagger v2会生成一个错误的json: { “value”: “{\”swagger\”:\”2.0\”,\”info\”:{\”description\”:\”Api Documentation\”,\”version\”:\”1.0\”,\”title\”:\”Api Documentation\”,\”termsOfService\”:\”urn:tos\”,\”contact\”:{\”name\”:\”Contact Email\”},\”license\”:{\”name\”:\”Apache 2.0\”,\”url\”:\”http: […]

在Spring Boot 2中解开Thymeleaf中的Kotlin HashMap

我有一个Kotlin函数,它创建一个带有hashmap的模型,如下所示 @GetMapping(“/”) fun index(model: Model): Mono { model.addAttribute(“images”, imageService.findAllImages()?.flatMap { image -> Mono.just(image) .zipWith(repository.findByImageId(image?.id!!).collectList()) .map({ imageAndComments: Tuple2<Image?, MutableList> -> hashMapOf( “id” to imageAndComments.t1?.id, “name” to imageAndComments.t1?.name, “comments” to imageAndComments.t2) }).log(“findAllImages”) }) model.addAttribute(“extra”, “DevTools can also detech code changes.”) return Mono.just(“index”) } Image.kt package learningspringboot.images import org.springframework.data.annotation.Id data class Image(@Id var id: String? = null, var […]