Generated-output differences

quicktype output changed between the PR base and tested PR merge revisions.
← Back to the pull request
3test cases
3files differ
2modified
1new
0deleted
49changed lines
+49 −0insertions / deletions
Base 94fefaf04fde7b4f921703d52c0378783fa2c831 · PR merge 885eadb1ae08dd1e5ddce9a39bebadc99d142f3d · Head 38711c7c5b2e8574fe1a10b397acddbc510143f8 · raw patch
Test case

test/inputs/json/samples/kitchen-sink.json

1 generated file · +2 −0
Mpikedefault / TopLevel.pmod+2 −0
@@ -58,9 +58,11 @@ TopLevel TopLevel_from_JSON(mixed json) {
5858 retval.different_things = json["differentThings"];
5959 retval.double_value = (float)json["doubleValue"];
6060 retval.int_value = json["intValue"];
61+ foreach (json["mapValue"]; mixed _; mixed value) if (stringp(value)) error("Unexpected string");
6162 retval.map_value = json["mapValue"];
6263 retval.name_with_spaces = json["name with spaces"];
6364 retval.null_value = json["nullValue"];
65+ foreach (json["nullableMapValue"]; mixed _; mixed value) if (stringp(value)) error("Unexpected string");
6466 retval.nullable_map_value = json["nullableMapValue"];
6567 retval.people = json["people"];
6668 retval.person = json["person"];
Test case

test/inputs/schema/class-with-additional.schema

1 generated file · +46 −0
Aschema-kotlindefault / TopLevel.kt+46 −0
@@ -0,0 +1,46 @@
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(MapValue::class, { MapValue.fromJson(it) }, { it.toJson() }, true)
19+
20+data class TopLevel (
21+ val map: Map<String, MapValue>? = null
22+) {
23+ public fun toJson() = klaxon.toJsonString(this)
24+
25+ companion object {
26+ public fun fromJson(json: String) = klaxon.parse<TopLevel>(json)
27+ }
28+}
29+
30+sealed class MapValue {
31+ class BoolValue(val value: Boolean) : MapValue()
32+ class DoubleValue(val value: Double) : MapValue()
33+
34+ public fun toJson(): String = klaxon.toJsonString(when (this) {
35+ is BoolValue -> this.value
36+ is DoubleValue -> this.value
37+ })
38+
39+ companion object {
40+ public fun fromJson(jv: JsonValue): MapValue = when (jv.inside) {
41+ is Boolean -> BoolValue(jv.boolean!!)
42+ is Double, is Int, is Long -> DoubleValue(jv.double ?: jv.int?.toDouble() ?: jv.longValue?.toDouble()!!)
43+ else -> throw IllegalArgumentException()
44+ }
45+ }
46+}
Test case

test/inputs/schema/vega-lite.schema

1 generated file · +1 −0
Mschema-pikedefault / TopLevel.pmod+1 −0
@@ -269,6 +269,7 @@ Config Config_from_JSON(mixed json) {
269269 retval.padding = json["padding"];
270270 retval.point = json["point"];
271271 retval.projection = json["projection"];
272+ foreach (json["range"]; mixed _; mixed value) if (stringp(value)) error("Unexpected string");
272273 retval.range = json["range"];
273274 retval.rect = json["rect"];
274275 retval.rule = json["rule"];
No generated files match these filters.