ron
04/04/2017, 9:04 PMedvin
04/04/2017, 9:05 PMsave
is a method on an instance of JsonModel, but load cannot be, since you want to create one from a file. There is a loadJsonObject()
though.edvin
04/04/2017, 9:06 PMloadJsonModel
, which calls loadJsonObject
under the covers.edvin
04/04/2017, 9:06 PMron
04/04/2017, 9:07 PMron
04/04/2017, 9:07 PM@Test fun testCategories(){
val parent = PhotoCategory("top");
parent.children.add(PhotoCategory("child 1"))
parent.children[0].children.add(PhotoCategory("child 1.1"))
parent.children.add(PhotoCategory("child 2"))
println(parent)
val builder = JsonBuilder()
parent.toJSON(builder)
println(builder.build().toPrettyString())
}
ron
04/04/2017, 9:08 PMron
04/04/2017, 9:08 PM{
"name": "top",
"dropAllowed": true,
"children": [
{
"name": "child 1",
"dropAllowed": true,
"children": [
{
"name": "child 1.1",
"dropAllowed": true
}
]
},
{
"name": "child 2",
"dropAllowed": true
}
]
}
ron
04/04/2017, 9:09 PMedvin
04/04/2017, 9:09 PMparent.toJSON().toPrettyString()
instead of those three last lines 🙂edvin
04/04/2017, 9:09 PMedvin
04/04/2017, 9:10 PMPhotoCategory
just needs to have a no args constructor and implement those two methods.ron
04/04/2017, 9:12 PMtoJSON
and update
?edvin
04/04/2017, 9:14 PMedvin
04/04/2017, 9:15 PMKotlin: Configuring the compilation environment
for a long time.ron
04/04/2017, 9:16 PMron
04/04/2017, 9:16 PMoverride fun toJSON(json: JsonBuilder) {
with(json){
add("name", name)
add("dropAllowed", dropAllowed)
add("children", children.toJSON())
}
}
override fun updateModel(json: JsonObject) {
with(json){
name = json.getString("name")
dropAllowed = json.getBoolean("dropAllowed")
children.setAll(json.getJsonArray("children").toModel())
}
}
edvin
04/04/2017, 9:18 PMedvin
04/04/2017, 9:19 PMloadJsonModel
from String of course 🙂edvin
04/04/2017, 9:21 PMval loadedParent: PhotoCategory = loadJsonModel(jsonString)
edvin
04/04/2017, 9:21 PMron
04/04/2017, 9:23 PMedvin
04/04/2017, 9:24 PMedvin
04/04/2017, 9:24 PMron
04/04/2017, 9:30 PMron
04/04/2017, 9:30 PMron
04/04/2017, 9:31 PMnimakro
04/04/2017, 9:39 PM