Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
3test cases
3files differ
1modified
2new
0deleted
56changed lines
+55 −1insertions / deletions
Base a96bd7ea3918b4e7b1c808c9eb9901dff6254ee9 · PR merge 7a463a88b9eb749d185e08287da92ba5f195a369 · Head 3491d70b545af30f78b24550684888b766f1f05a · raw patch
Test case

test/inputs/json/priority/issue2680-scalar-array.json

1 generated file · +1 −1
Mkotlindefault / TopLevel.kt+1 −1
@@ -12,6 +12,6 @@ class TopLevel(elements: Collection<Long>) : ArrayList<Long>(elements) {
1212 public fun toJson() = klaxon.toJsonString(this)
1313
1414 companion object {
15- public fun fromJson(json: String) = TopLevel(klaxon.parseArray<Long>(json)!!)
15+ public fun fromJson(json: String) = TopLevel(klaxon.parseArray<Any>(json)!!.map { when (it) { is Int -> it.toLong(); is Long -> it; else -> throw IllegalArgumentException() } })
1616 }
1717 }
Test case

test/inputs/schema/issue2680-top-level-array.schema

1 generated file · +17 −0
Aschema-kotlindefault / TopLevel.kt+17 −0
@@ -0,0 +1,17 @@
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 val klaxon = Klaxon()
10+
11+class TopLevel(elements: Collection<Long>) : ArrayList<Long>(elements) {
12+ public fun toJson() = klaxon.toJsonString(this)
13+
14+ companion object {
15+ public fun fromJson(json: String) = TopLevel(klaxon.parseArray<Any>(json)!!.map { when (it) { is Int -> it.toLong(); is Long -> it; else -> throw IllegalArgumentException() } })
16+ }
17+}
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.