commit | c345b20f33a1fb9c84b70665c0d25168643e9934 | [log] [tgz] |
---|---|---|
author | Leonid Startsev <sandwwraith@gmail.com> | Thu Aug 03 15:38:10 2017 +0300 |
committer | Leonid Startsev <sandwwraith@gmail.com> | Thu Aug 03 15:38:10 2017 +0300 |
tree | 8f8b3460b7e09b8aa354095427f4ec932d08a941 | |
parent | 1cf5d38afca5fecf4eecb0245b6c65aa356a012e [diff] |
Get rid of `javax` dependency
Kotlin serialization plugin consists of three parts: a gradle compiler plugin, an IntelliJ plugin and a runtime library. This is the runtime library. To build any project with serialization (including this one), you'll need a serialization gradle plugin. To have a proper syntax highlighting in the Intellij IDEA, you'll need an IDEA plugin.
Runtime library provides basic classes:
Interfaces which are called by compiler-generated code (KInput
, KOutput
)
Basic skeleton implementations of these interfaces in which you should override some methods if you want to implement custom data format (ElementValueInput/Output
, NamedValueInput/Output
, ElementValueTransformer
)
Some internal classes like built-ins and collections serializers
Also, runtime library provides some ready-to-use serialization formats: JSON and CBOR.
Make sure you have serialization gradle plugin installed to your local maven repository. Then, run ./gradlew publishToMavenLocal
. After that, you can include this library in arbitrary projects like usual gradle dependency:
repositories { jcenter() mavenLocal() } dependencies { compile "org.jetbrains.kotlinx:serialization-runtime:1.1-SNAPSHOT" }
import kotlinx.serialization.* @Serializable data class Data(val a: Int, @Optional val b: String = "42") fun main(args: Array<String>) { println(JSON.stringify(Data(42))) // {"a": 42, "b": "42"} val obj = JSON.parse<Data>("""{"a":42}""") // Data(a=42, b="42") }
More complicated examples and examples of implementing custom formats can be found in examples
folder. Detailed documentation located in DOC.md.