diff --git a/modules/openapi-generator/src/main/resources/kotlin-spring/apiUtil.mustache b/modules/openapi-generator/src/main/resources/kotlin-spring/apiUtil.mustache index 4837075c136..8ae90f20aa7 100644 --- a/modules/openapi-generator/src/main/resources/kotlin-spring/apiUtil.mustache +++ b/modules/openapi-generator/src/main/resources/kotlin-spring/apiUtil.mustache @@ -12,9 +12,9 @@ object ApiUtil { fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { try { val res = req.getNativeResponse(HttpServletResponse::class.java) - res.setCharacterEncoding("UTF-8") - res.addHeader("Content-Type", contentType) - res.getWriter().print(example) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) } catch (e: IOException) { throw RuntimeException(e) } diff --git a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/ApiUtil.kt index 958a6f3ebfe..88e892d0f49 100644 --- a/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/ApiUtil.kt +++ b/samples/server/petstore/kotlin-springboot-modelMutable/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -9,9 +9,9 @@ object ApiUtil { fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { try { val res = req.getNativeResponse(HttpServletResponse::class.java) - res.setCharacterEncoding("UTF-8") - res.addHeader("Content-Type", contentType) - res.getWriter().print(example) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) } catch (e: IOException) { throw RuntimeException(e) } diff --git a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/ApiUtil.kt b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/ApiUtil.kt index 958a6f3ebfe..88e892d0f49 100644 --- a/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/ApiUtil.kt +++ b/samples/server/petstore/kotlin-springboot/src/main/kotlin/org/openapitools/api/ApiUtil.kt @@ -9,9 +9,9 @@ object ApiUtil { fun setExampleResponse(req: NativeWebRequest, contentType: String, example: String) { try { val res = req.getNativeResponse(HttpServletResponse::class.java) - res.setCharacterEncoding("UTF-8") - res.addHeader("Content-Type", contentType) - res.getWriter().print(example) + res?.characterEncoding = "UTF-8" + res?.addHeader("Content-Type", contentType) + res?.writer?.print(example) } catch (e: IOException) { throw RuntimeException(e) }