I have a Java Backend that serves an openapi.json specification. Its purpose is that is it possible to create an API Client through openapi-generator. This is what I did. The Client comes out just fine, every class is perfect, they all have the properties they should be having and so on. One example is this class:
public final data class Project public constructor(
name: kotlin.String,
title: kotlin.String,
previewUrl: kotlin.String,
connections: kotlin.collections.List<kotlin.String>? /* = compiled code */,
mapWindows: kotlin.collections.List<kotlin.String>? /* = compiled code */,
ribbons: kotlin.collections.List<kotlin.String>? /* = compiled code */
) {
@field:com.fasterxml.jackson.annotation.JsonProperty public final val connections: kotlin.collections.List<kotlin.String>? /* compiled code */
@field:com.fasterxml.jackson.annotation.JsonProperty public final val mapWindows: kotlin.collections.List<kotlin.String>? /* compiled code */
@field:com.fasterxml.jackson.annotation.JsonProperty public final val name: kotlin.String /* compiled code */
@field:com.fasterxml.jackson.annotation.JsonProperty public final val previewUrl: kotlin.String /* compiled code */
@field:com.fasterxml.jackson.annotation.JsonProperty public final val ribbons: kotlin.collections.List<kotlin.String>? /* compiled code */
@field:com.fasterxml.jackson.annotation.JsonProperty public final val title: kotlin.String /* compiled code */
}
As you see, this class looks just fine.
Then I have a service containing functions as the following:
public final fun getProjects():
kotlin.collections.List<bla.bla.bla.Project> {
/* compiled code */
}
So, what do I expect when executing this class? As it returns a List of Projects I also expect to get a List of Projects. But instead I get a List of LinkedHashMaps.
As soon as I worked with these Lists the App will get an exception. It is not possible to cast these LinkedHashMaps over to Project. As soon as I get this List it means 'Game Over'.
Actually, I have no clue what to do now. I also tried to use moshi or gson when creating the api client but sadly we have really deeply nested classes that did not work out with these.
Did anyone ever experience something similar?
Well, apparently that was an easy fix. Somehow Jackson does not like kotlin.collection.List, but it does like Arrays. So I added this line to config.json:
"collectionType": "array"
And that's it. Now it returns Arrays with the proper type.