summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeonid Startsev <sandwwraith@gmail.com>2017-12-22 20:09:53 +0300
committerLeonid Startsev <sandwwraith@gmail.com>2017-12-22 20:09:53 +0300
commite8fb8a11e50277106bf1d7e12f4ef605245cc73a (patch)
treeada3012d32099493c7844d12feca8b444b28d090
parentdda7d17fe3b1f3c2882ca14b24d6b776c3fa0c12 (diff)
downloadkotlinx.serialization-e8fb8a11e50277106bf1d7e12f4ef605245cc73a.tar.gz
Updated docs and samples for v0.4
-rw-r--r--README.md12
-rw-r--r--docs/custom_serializers.md35
-rw-r--r--example-js/build.gradle4
-rw-r--r--example-jvm/README.md2
-rw-r--r--example-jvm/build.gradle5
-rw-r--r--example-jvm/pom.xml4
6 files changed, 33 insertions, 29 deletions
diff --git a/README.md b/README.md
index ec7588a6..2f5c2319 100644
--- a/README.md
+++ b/README.md
@@ -57,7 +57,9 @@ More examples of various kinds of Kotlin classes that can be serialized can be f
## Setup
-Using Kotlin Serialization requires Kotlin compiler `1.1.50` or higher, recommended version is `1.2.0`.
+Using Kotlin Serialization requires Kotlin compiler `1.1.50` or higher, recommended version is `1.2.10` or `1.2.20-eap-11`
+Also, it's recommended to install [additional IDEA plugin](#working-in-intellij-idea) for better IDE experience. Otherwise,
+some valid code will be shown as red and builds will have to be launched from console or build system tasks panel.
Example projects on JVM are available for [Gradle](example-jvm/build.gradle) and [Maven](example-jvm/pom.xml).
### Gradle/JVM
@@ -66,8 +68,8 @@ Ensure the proper version of Kotlin and add dependencies on plugin in addition t
```gradle
buildscript {
- ext.kotlin_version = '1.2.0'
- ext.serialization_version = '0.3'
+ ext.kotlin_version = '1.2.10'
+ ext.serialization_version = '0.4'
repositories {
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
@@ -120,8 +122,8 @@ Ensure the proper version of Kotlin and serialization version:
```xml
<properties>
- <kotlin.version>1.2.0</kotlin.version>
- <serialization.version>0.3</serialization.version>
+ <kotlin.version>1.2.10</kotlin.version>
+ <serialization.version>0.4</serialization.version>
</properties>
```
diff --git a/docs/custom_serializers.md b/docs/custom_serializers.md
index 3447189d..24031a29 100644
--- a/docs/custom_serializers.md
+++ b/docs/custom_serializers.md
@@ -80,6 +80,9 @@ object DateSerializer: KSerializer<Date> {
}
```
+If your class has generic type arguments, it shouldn't be an object.
+It must be a class with visible primary constructor, where its arguments are `KSerializer<T0>, KSerializer<T1>, etc..` - one for each type argument of your class.
+
### JS note
Due to an [issue](https://youtrack.jetbrains.com/issue/KT-11586), it's impossible now to write
@@ -107,11 +110,26 @@ object MyDataSerializer: KSerializer<MyData> {
}
```
+## Using custom serializers
+
+Recommended way of using custom serializers is to give a clue to plugin about which serializer use for specified property,
+using annotation in form `@Serializable(with = SomeKSerializer::class)`:
+
+```kotlin
+@Serializable
+data class MyWrapper(
+ val id: Int,
+ @Serializable(with=MyExternalSerializer::class) val data: MyData
+)
+```
+
+This will affect generating of `save`/`load` methods only for this dedicated class, and allows plugin to resolve serializer at compile-time to reduce runtime overhead.
+
## Registering and context
By default, all serializers are resolved by plugin statically when compiling serializable class.
This gives us type-safety, performance and eliminates reflection usage to minimum. However, if there is no
-`@Serializable` annotation of class, in general, it is impossible to know at compile time which serializer to
+`@Serializable` annotation of class and no `@Serializable(with=...)` on property, in general, it is impossible to know at compile time which serializer to
use - user can define more than one external serializer, or define them in other module, or even it's a class from
library which doesn't know anything about serialization.
@@ -139,18 +157,3 @@ fun foo(b: B): Pair<String, ByteArray> {
return json.stringify(b) to cbor.dump(b)
}
```
-
-## Overriding serializers
-
-If you want to give a clue to plugin about which serializer use for specified property,
-you may use annotation in form `@Serializable(with = SomeKSerializer::class)`:
-
-```kotlin
-@Serializable
-data class MyWrapper(
- val id: Int,
- @Serializable(with=MyExternalSerializer::class) val data: MyData
-)
-```
-
-This will affect generating of `save`/`load` methods only for this dedicated class. \ No newline at end of file
diff --git a/example-js/build.gradle b/example-js/build.gradle
index 41cbfbbd..80f5198a 100644
--- a/example-js/build.gradle
+++ b/example-js/build.gradle
@@ -17,8 +17,8 @@
version '1.0-SNAPSHOT'
buildscript {
- ext.kotlin_version = '1.2.0'
- ext.serialization_version = '0.3'
+ ext.kotlin_version = '1.2.10'
+ ext.serialization_version = '0.4'
ext.web_path = 'web'
repositories {
diff --git a/example-jvm/README.md b/example-jvm/README.md
index c68228d6..e73db5fc 100644
--- a/example-jvm/README.md
+++ b/example-jvm/README.md
@@ -3,5 +3,5 @@
This project showcases various built-in and custom serialization formats and
test cases for classes that can be serialized into those formats.
-Use `./gradlew runApp` to run a self-test showing how classes are serialization into those formats
+Use `./gradlew runApp` to run a self-test showing how classes are serialized into those formats
and back into Kotlin.
diff --git a/example-jvm/build.gradle b/example-jvm/build.gradle
index 62391c27..a15ee337 100644
--- a/example-jvm/build.gradle
+++ b/example-jvm/build.gradle
@@ -15,8 +15,8 @@
*/
buildscript {
- ext.kotlin_version = '1.2.0'
- ext.serialization_version = '0.3'
+ ext.kotlin_version = '1.2.10'
+ ext.serialization_version = '0.4'
repositories {
jcenter()
@@ -46,7 +46,6 @@ sourceSets {
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
- compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
}
diff --git a/example-jvm/pom.xml b/example-jvm/pom.xml
index 8070552b..3c1bafec 100644
--- a/example-jvm/pom.xml
+++ b/example-jvm/pom.xml
@@ -45,8 +45,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <kotlin.version>1.2.0</kotlin.version>
- <serialization.version>0.3</serialization.version>
+ <kotlin.version>1.2.10</kotlin.version>
+ <serialization.version>0.4</serialization.version>
</properties>
<dependencies>