You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
post fails to deserialise List<UUID> in body, even though Swagger knows that the correct type is UUID. Kotlin says it's UUID, however during runtime, it's String, which results in ClassCastException when accessing the element. My project is using latest Jackson.
Minimal working example:
fun NormalOpenAPIRoute.testRoute() {
route("/test").post<Unit, String, List<UUID>> { _, listUuids ->println(listUuids.joinToString(separator =" - ") { it.toString() }) // access on the element throws java.lang.ClassCastException
respond("OK")
}
}
java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.UUID (java.lang.String and java.util.UUID are in module java.base of loader 'bootstrap')
at com.wire.troy.routing.ConversationRoutesKt$testRoute$1$1.invoke(ConversationRoutes.kt:81)
at kotlin.text.StringsKt__AppendableKt.appendElement(Appendable.kt:85)
at kotlin.collections.CollectionsKt___CollectionsKt.joinTo(_Collections.kt:3344)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString(_Collections.kt:3361)
at kotlin.collections.CollectionsKt___CollectionsKt.joinToString$default(_Collections.kt:3360)
To be honest this is not an open API generator issue. It is mostly related to generic types information erasure at runtime. Jackson can't get generic type information so it is not able to propper parse this type. This will not work for top-level generic objects. But it should be fine for such a case. class UuidsList(val values: List<UUID>
But this will require changing payload from list of uuids, to object that contains a list of UUIDs
Another solution will be to use post "x-www-form-urlencoded" content type with key-value pairs. But this will look exactly the same as the previous example (UuidsList)
We can use inheritance to preserve generic type at runtime, But unfortunately, this will not work out of the box as code from DefaultCollectionSchemaProvider needs to be adjusted as for now it only handles current class generic arguments without supertype support.
post
fails to deserialiseList<UUID>
in body, even though Swagger knows that the correct type isUUID
. Kotlin says it'sUUID
, however during runtime, it'sString
, which results inClassCastException
when accessing the element. My project is using latest Jackson.Minimal working example:
Request:
Debugger:
Exception:
And the
openapi.json
The text was updated successfully, but these errors were encountered: