Navigation Menu

Skip to content

Commit

Permalink
Update to 1.3.40 eap2;
Browse files Browse the repository at this point in the history
Fix obsolete/broken links
  • Loading branch information
sandwwraith committed Jun 13, 2019
1 parent 45241c1 commit 6158c39
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
14 changes: 7 additions & 7 deletions docs/custom_serializers.md
Expand Up @@ -99,7 +99,7 @@ So crucial part here is to make a `when` over an index of an incoming element:
```kotlin
override fun deserialize(input: Decoder): BinaryPayload {
val inp: CompositeDecoder = input.beginStructure(descriptor)
lateinit var req: ByteArray // consider using flags or bit mask if you
lateinit var req: ByteArray // consider using flags or bit mask if you
lateinit var res: ByteArray // need to read nullable non-optional properties
loop@ while (true) {
when (val i = inp.decodeElementIndex(descriptor)) {
Expand All @@ -114,7 +114,7 @@ override fun deserialize(input: Decoder): BinaryPayload {
}
```

You can see it in action [in tests](https://github.com/kotlin/kotlinx.serialization/blob/a4c41392bb735a36788db1d789ec60afdbad3ca8/runtime/common/src/test/kotlin/kotlinx/serialization/features/BinaryPayloadExampleTest.kt). Another useful example from tests is [custom serializer which uses ability to read JSON as tree](https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/common/src/test/kotlin/kotlinx/serialization/json/JsonTreeAndMapperTest.kt#L35).
You can see it in action [in tests](../runtime/commonTest/src/kotlinx/serialization/features/BinaryPayloadExampleTest.kt#L10). Another useful example from tests is [custom serializer which uses ability to read JSON as tree](../runtime/commonTest/src/kotlinx/serialization/json/JsonTreeAndMapperTest.kt#L35).

*Note:* this approach is not working for generic classes, see below.

Expand Down Expand Up @@ -159,7 +159,7 @@ object DateSerializer: KSerializer<Date> {
}
```

See it in action [here](https://github.com/kotlin/kotlinx.serialization/blob/a4c41392bb735a36788db1d789ec60afdbad3ca8/runtime/jvm/src/test/kotlin/kotlinx/serialization/features/SerializeJavaClassTest.kt).
See it in action [here](../runtime/jvmTest/src/kotlinx/serialization/features/SerializeJavaClassTest.kt).

### About generic serializers

Expand All @@ -180,7 +180,7 @@ Note that we haven't applied `@Serializable` on the class, because we can't cust
*Current limitation*: Because primary constructor in such case is generated by the compiler itself, not the plugin,
you have to override `descriptor` manually since it can't be initialized in non-synthetic constructor.

See full sample [here](https://github.com/kotlin/kotlinx.serialization/blob/a4c41392bb735a36788db1d789ec60afdbad3ca8/runtime/jvm/src/test/kotlin/kotlinx/serialization/features/GenericCustomSerializerTest.kt).
See full sample [here](../runtime/commonTest/src/kotlinx/serialization/features/GenericCustomSerializerTest.kt#L85).

## Using custom serializers

Expand All @@ -193,13 +193,13 @@ 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. It would also allow plugin to inject serializers for generic properties automatically.

### `UseSerializers` annotation

If you have a lot of serializable classes, which use, say `java.util.Date`, it may be inconvenient to annotate every property with this type with `@Serializable(with=MyJavaDateSerializer::class)`. For such purpose, a file-level annotation `UseSerializers` was introduced. With it, you can write `@file:UseSerializers(MyJavaDateSerializer::class)` and all properties of type `java.util.Date` in all classes in this file would be serialized with `MyJavaDateSerializer`. See [its documentation](https://github.com/kotlin/kotlinx.serialization/blob/c6dd98c8b96a69da82ab8229665e07614296f684/runtime/common/src/main/kotlin/kotlinx/serialization/Annotations.kt#L75) for more details.
If you have a lot of serializable classes, which use, say `java.util.Date`, it may be inconvenient to annotate every property with this type with `@Serializable(with=MyJavaDateSerializer::class)`. For such purpose, a file-level annotation `UseSerializers` was introduced. With it, you can write `@file:UseSerializers(MyJavaDateSerializer::class)` and all properties of type `java.util.Date` in all classes in this file would be serialized with `MyJavaDateSerializer`. See [its documentation](../runtime/commonMain/src/kotlinx/serialization/Annotations.kt#L74) for more details.

## Registering and context

Expand Down Expand Up @@ -242,4 +242,4 @@ val json2 = Json(context = binaryModule)
// in json2, Payload would be serialized with BinaryPayloadSerializer
```

See it in action [here](https://github.com/kotlin/kotlinx.serialization/blob/a4c41392bb735a36788db1d789ec60afdbad3ca8/runtime/jvm/src/test/kotlin/kotlinx/serialization/CustomSerializersJVMTest.kt#L96).
See it in action [here](../runtime/commonTest/src/kotlinx/serialization/features/ContextAndPolymorphicTest.kt#L86).
4 changes: 2 additions & 2 deletions docs/examples.md
@@ -1,6 +1,6 @@
# Serialization documentation and example cases

**Note**: Cases are presented here as a series of *unit-tests* using non-standard *unquoted* JSON for ease of presentation.
**Note**: Cases are presented here as a series of *unit-tests* using non-standard *unquoted* JSON for ease of presentation.
It was created as `val json = Json(JsonConfiguration.Stable.copy(unquoted = true))`.
Standards-compliant JSON is supported, too. Just use `.Stable` or `.Default` configurations or create your own.

Expand Down Expand Up @@ -57,7 +57,7 @@ Standards-compliant JSON is supported, too. Just use `.Stable` or `.Default` con

> Tip: you can omit default values during serialization with
`Json(encodeDefaults = false)` (see [here](runtime_usage.md#json)).

> Tip: Deprecated `@Optional` annotation was used in older version and older kotlin version.

Expand Down
6 changes: 3 additions & 3 deletions docs/runtime_usage.md
Expand Up @@ -59,7 +59,7 @@ but may be useful shorthand in some cases.
Functions which uses this or similar functionality are annotated
with [experimental](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-experimental/index.html)
annotation `kotlinx.serialization.ImplicitReflectionSerializer`.
Consult [annotation documentation](https://github.com/kotlin/kotlinx.serialization/blob/master/runtime/common/src/main/kotlin/kotlinx/serialization/SerialImplicits.kt#L11)
Consult [annotation documentation](../runtime/commonMain/src/kotlinx/serialization/SerialImplicits.kt#L8)
to learn about restrictions of this approach.
To learn how to use experimental annotations, look at theirs [KEEP](https://github.com/Kotlin/KEEP/blob/master/proposals/experimental.md)
or use [this guide](https://kotlinlang.org/docs/reference/experimental.html#using-experimental-apis).
Expand Down Expand Up @@ -119,7 +119,7 @@ inline fun <reified T : Any> parse(str: String): T = parse(T::class.serializer()

`stringify` transforms object to string, `parse` parses. No surprises.

Besides this, functions `toJson` and `fromJson` allow converting @Serializable Kotlin object to and from [abstract JSON syntax tree](https://github.com/Kotlin/kotlinx.serialization/blob/master/runtime/common/src/main/kotlin/kotlinx/serialization/json/JsonElement.kt). To build JSON AST from String, use `parseJson`.
Besides this, functions `toJson` and `fromJson` allow converting @Serializable Kotlin object to and from [abstract JSON syntax tree](../runtime/commonMain/src/kotlinx/serialization/json/JsonElement.kt#L23). To build JSON AST from String, use `parseJson`.

You can also use one of predefined instances, like `Json.plain`, `Json.indented`, `Json.nonstrict` or `Json.unquoted`. API is duplicated in companion object, so `Json.parse(...)` equals to `Json.plain.parse(...)`.

Expand Down Expand Up @@ -179,7 +179,7 @@ Other known issues and limitations:
* Packed repeated fields are not supported

More examples of mappings from proto definitions to Koltin classes can be found in test data:
[here](../runtime/jvm/src/test/proto/test_data.proto) and [here](../runtime/jvm/src/test/kotlin/kotlinx/serialization/formats/RandomTests.kt)
[here](../runtime/testProto/test_data.proto) and [here](../runtime/jvmTest/src/kotlinx/serialization/formats/RandomTests.kt)

## Useful classes

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Expand Up @@ -3,9 +3,9 @@
#

group=org.jetbrains.kotlinx
version=0.11.1
version=0.11.1-1.3.40-eap-67

kotlin.version=1.3.30
kotlin.version=1.3.40-eap-67

# This version take precedence if 'bootstrap' property passed to project
kotlin.version.snapshot=1.3-SNAPSHOT
Expand Down
15 changes: 9 additions & 6 deletions gradle/publishing.gradle
Expand Up @@ -63,11 +63,12 @@ afterEvaluate {
// Rename artifacts for backward compatibility
publications.all {
def type = it.name
// println("Configuring $type")
logger.info("Configuring $type")
switch (type) {
case 'kotlinMultiplatform':
it.artifactId = "$variantName-native"
it.artifact emptyJar
// bug in bintray plugin? jvm publication has empty jar after this
// it.artifact emptyJar
// it.artifact stubJavadoc
it.artifact sourcesJar
break
Expand All @@ -80,11 +81,12 @@ afterEvaluate {
it.artifactId = "$variantName"
break

default:
case 'js':
case 'native': // native most probably unused but I'll leave it just in case
it.artifactId = "$variantName-$type"
break
}
// println("Artifact id = ${it.artifactId}")
logger.info("Artifact id = ${it.artifactId}")

pom.withXml(configureMavenCentralMetadata)
}
Expand Down Expand Up @@ -114,7 +116,8 @@ private void disableMetadataPublication() {
onlyIf { false }
}
} else {
publication.artifact emptyJar
// bug in bintray plugin? jvm publication has empty jar after this
// publication.artifact emptyJar
}
}
}
Expand All @@ -129,7 +132,7 @@ bintrayUpload.dependsOn publishToMavenLocal
// This is for easier debugging of bintray uploading problems
bintrayUpload.doFirst {
publications = project.publishing.publications.findAll { !it.name.contains('-test') }.collect {
println("Uploading artifact '$it.groupId:$it.artifactId:$it.version' from publication '$it.name'")
logger.info("Uploading artifact '$it.groupId:$it.artifactId:$it.version' from publication '$it.name'")
it
}
}
Expand Up @@ -85,7 +85,6 @@ class ContextAndPolymorphicTest {
@Test
fun testDifferentRepresentations() {
val simpleModule = serializersModule(PayloadSerializer)
// MapModule and CompositeModule are also available
val binaryModule = serializersModule(BinaryPayloadSerializer)

val json1 = Json { useArrayPolymorphism = true; serialModule = simpleModule }
Expand Down

0 comments on commit 6158c39

Please sign in to comment.