commit | d604fbe1f98ac298e6dc5e4431480f1726c58c18 | [log] [tgz] |
---|---|---|
author | Leonid Startsev <sandwwraith@gmail.com> | Thu Aug 03 11:21:08 2017 +0300 |
committer | Leonid Startsev <sandwwraith@gmail.com> | Thu Aug 03 11:21:08 2017 +0300 |
tree | 556053da05c7cdc4abcfe0ff9b9154606e3294cf | |
parent | 6d6aaf41a3a535d660c3c0d324cf05c2ba82ead9 [diff] |
Documentation fixes
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.