Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
1test cases
1files differ
0modified
1new
0deleted
37changed lines
+37 −0insertions / deletions
Base a96bd7ea3918b4e7b1c808c9eb9901dff6254ee9 · PR merge 5f3ada131ed8d6b94361e0391171bc361aea1f02 · Head c1cfe3d45dc2ff61e565b856c030c254ac5cb245 · raw patch
Test case

test/inputs/schema/top-level-enum.schema

1 generated file · +37 −0
Aschema-kotlindefault / TopLevel.kt+37 −0
@@ -0,0 +1,37 @@
1+// To parse the JSON, install Klaxon and do:
2+//
3+// val topLevel = TopLevel.fromJson(jsonString)
4+
5+package quicktype
6+
7+import com.beust.klaxon.*
8+
9+private fun <T> Klaxon.convert(k: kotlin.reflect.KClass<*>, fromJson: (JsonValue) -> T, toJson: (T) -> String, isUnion: Boolean = false) =
10+ this.converter(object: Converter {
11+ @Suppress("UNCHECKED_CAST")
12+ override fun toJson(value: Any) = toJson(value as T)
13+ override fun fromJson(jv: JsonValue) = fromJson(jv) as Any
14+ override fun canConvert(cls: Class<*>) = cls == k.java || (isUnion && cls.superclass == k.java)
15+ })
16+
17+private val klaxon = Klaxon()
18+ .convert(TopLevel::class, { TopLevel.fromValue(it.string!!) }, { "\"${it.value}\"" })
19+
20+enum class TopLevel(val value: String) {
21+ One("one"),
22+ Three("three"),
23+ Two("two");
24+
25+ public fun toJson() = klaxon.toJsonString(value)
26+
27+ companion object {
28+ public fun fromJson(json: String) = fromValue(klaxon.parseArray<String>("[${json}]")!![0])
29+
30+ public fun fromValue(value: String): TopLevel = when (value) {
31+ "one" -> One
32+ "three" -> Three
33+ "two" -> Two
34+ else -> throw IllegalArgumentException()
35+ }
36+ }
37+}
No generated files match these filters.