https://kotlinlang.org logo
#ktor
Title
# ktor
b

bitkid

06/01/2022, 12:05 PM
hi! i am currently updating to ktor2 and i am moving from the location API to the resource API. in my URL parameters i used to have a parameter defined like this val format: ImportFormat = ImportFormat.NDJSONLD (where import format is an enum). it was possible to omit the enum parameter in the location API and it just took the default value. now i get the exception Can't transform call to resource with an underlying NPE. any ideas?
the whole thing looks like this
Copy code
@Serializable
@Resource("/api/import-results")
class ImportResultData(
    val resource: String,
    val format: ImportFormat = ImportFormat.NDJSONLD
)
r

Rustam Siniukov

06/01/2022, 12:10 PM
Can you share stacktrace, please?
maybe i have to configure the serializer used?
btw it also doesnt work to make it just nullable val format: ImportFormat?
stacktrace looks the same
r

Rustam Siniukov

06/01/2022, 12:27 PM
Ok, i reproduced it. Will open PR shortly
b

bitkid

06/01/2022, 12:59 PM
any fast workaround for 2.0.1?
r

Rustam Siniukov

06/01/2022, 1:23 PM
I can’t think of any workaround for now
b

bitkid

06/01/2022, 1:32 PM
i found one .. just write a custom serializer for the enum like this
and then use
Copy code
@Serializable(with = ImportFormatSerializer::class) val format: ImportFormat = ImportFormat.NDJSONLD
2 Views