Greeting all,
I’ve done a proof of concept JSON wrapper for Jackson based on Play’s JSON support and ended up with: https://github.com/andrewoma/kson
It’s the result of an afternoon’s hacking, so it’s definitely not a production library. However, it seemed promising, so thought I’d publish it as is.
Here’s an example from https://github.com/andrewoma/kson/blob/master/kson/src/test/java/com/github/andrewoma/kson/JsValueTest.kt
val value = JsObject("firstName" to "Andrew".json,"lastName" to "O'Malley".json,"age" to 21.json,"adult" to true.json,"address" to JsObject("number" to "88".json,"street" to "Chapel Street".json,"suburb" to "Windsor".json,"state" to "VIC".json,"postCode" to "3181".json),"pets" to JsArray(listOf(JsObject("kind" to "dog".json,"name" to "Rover".json),JsObject("kind" to "cat".json,"name" to "Kitty".json))))
I’m still keen to experiment with some kind of builder syntax (or hear of other experiments - I know about klaxon).
A question for the Kotlin devs: is the conversion operator still planned for Kotlin? See http://youtrack.jetbrains.com/issue/KT-1752#comment=27-318887
If feel uneasy adding extension functions and properties to base types like String. A conversion operator (with the correct precedence) would allow things like the following without possible namespace clashes:
fun String.convert() : JsValue = JsString(this)
Then the syntax above would become (without a chance of clashing with some other library):
"firstName" to ~"Andrew"
Cheers,
Andrew