I tried creating types from multiple examples returned by an API. The result was a Kotlin file that did not compile. It creates an enum class where one of the enum values has the same name as the enum itself which will not work (in general, JVM enum values should not be CamelCased; SCREAMING_SNAKE_CASE or lowercaseCamelCase are preferred).
The generated code is:
enum class Category(val value: String) {
Category(" "), // Does not compile because enum value is same as the class name
Empty("\u0000");
companion object {
fun fromValue(value: String): Category = when (value) {
" " -> Category
"\u0000" -> Empty
else -> throw IllegalArgumentException()
}
}
}
The JSON input that produces this error are a bunch of files with a property that contain only two possible values (omitting the rest here for brevity): { "category" : " " } and { "category" : "\u0000" }. I invoked quicktype with npx quicktype --src someclass --src-lang json --lang kotlin --package com.example --framework jackson --out src/main/kotlin/someclass.kt
I've uploaded the above code (plus enough .json files that enum conversion happens) to https://publicstash.s3.us-west-1.amazonaws.com/quicktype-bug-report.tar.gz
The package includes the generation code (the quicktype-convert script) as well as a quick Gradle file that starts a build (just run ./gradlew compileKotlin, you only need a recent Java installed.. and use gradlew.bat if on Windows).
I tried creating types from multiple examples returned by an API. The result was a Kotlin file that did not compile. It creates an enum class where one of the enum values has the same name as the enum itself which will not work (in general, JVM enum values should not be CamelCased; SCREAMING_SNAKE_CASE or lowercaseCamelCase are preferred).
The generated code is:
The JSON input that produces this error are a bunch of files with a property that contain only two possible values (omitting the rest here for brevity):
{ "category" : " " }and{ "category" : "\u0000" }. I invoked quicktype withnpx quicktype --src someclass --src-lang json --lang kotlin --package com.example --framework jackson --out src/main/kotlin/someclass.ktI've uploaded the above code (plus enough .json files that enum conversion happens) to https://publicstash.s3.us-west-1.amazonaws.com/quicktype-bug-report.tar.gz
The package includes the generation code (the
quicktype-convertscript) as well as a quick Gradle file that starts a build (just run./gradlew compileKotlin, you only need a recent Java installed.. and usegradlew.batif on Windows).