From 11edd12ea947c0519278316fbd6439a30b957d78 Mon Sep 17 00:00:00 2001
From: Yonatan Karp-Rudin <yonatan.karp@sumup.com>
Date: Sat, 10 Dec 2022 10:02:43 +0100
Subject: [PATCH] Fix Retrofit template with Jackson (Fix #8147)

This commit amends the `ApiClient` template for Retrofit. It fixes a bug where the Retrofit client uses Jackson as the serialization library.

Until now, the `ApiClient` could not be compiled when using the Jackson library (default in SpringBoot applications), as the constructor of the class had the following parameter:

`private val serializerBuilder: Builder = Serializer.Builder,`

The change done in the commit, is to ensure that in case of Jackson, the right property of the `Serializer` class is assigned
---
 .../jvm-retrofit2/infrastructure/ApiClient.kt.mustache       | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache
index 4b48bdcb7da..405091b5e0c 100644
--- a/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache
+++ b/modules/openapi-generator/src/main/resources/kotlin-client/libraries/jvm-retrofit2/infrastructure/ApiClient.kt.mustache
@@ -48,6 +48,9 @@ import retrofit2.converter.gson.GsonConverterFactory
 import com.squareup.moshi.Moshi
 import retrofit2.converter.moshi.MoshiConverterFactory
 {{/moshi}}
+{{#jackson}}
+import com.fasterxml.jackson.databind.ObjectMapper
+{{/jackson}}
 
 {{#kotlinx_serialization}}
 import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
@@ -58,7 +61,7 @@ import okhttp3.MediaType.Companion.toMediaType
 {{#nonPublicApi}}internal {{/nonPublicApi}}class ApiClient(
     private var baseUrl: String = defaultBasePath,
     private val okHttpClientBuilder: OkHttpClient.Builder? = null{{^kotlinx_serialization}},
-    private val serializerBuilder: {{#gson}}Gson{{/gson}}{{#moshi}}Moshi.{{/moshi}}Builder = Serializer.{{#gson}}gson{{/gson}}{{#moshi}}moshi{{/moshi}}Builder{{/kotlinx_serialization}},
+    private val serializerBuilder: {{#gson}}GsonBuilder{{/gson}}{{#moshi}}Moshi.Builder{{/moshi}}{{#jackson}}ObjectMapper{{/jackson}} = Serializer.{{#gson}}gsonBuilder{{/gson}}{{#moshi}}moshiBuilder{{/moshi}}{{#jackson}}jacksonObjectMapper{{/jackson}}{{/kotlinx_serialization}},
     private val callFactory : Call.Factory? = null,
     private val converterFactory: Converter.Factory? = null,
 ) {
-- 
GitLab