Slide 1

Slide 1 text

Yuki Shiho @shihochan Kotlin cross-platform / multi-format serialization shibuta.apk #26 in 2018/06/26

Slide 2

Slide 2 text

About me 志甫 侑紀 / YUKI SHIHO @shihochan Software Engineer at AbemaTV, Inc. @shihochandesu Shibuya.apk

Slide 3

Slide 3 text

8%#13&447PM 4"-&/080/

Slide 4

Slide 4 text

• What is kotlinx.serialization? • Performance • Which of serialization libraries? Agenda

Slide 5

Slide 5 text

What is kotlinx.serialization? • Kotlin / kotlinx.serialization • Supports Kotlin classes marked as @Serializable and standard collections • Formats: JSON, CBOR and Protobuf • Platform: Kotlin/JVM, Kotlin/JS

Slide 6

Slide 6 text

import kotlinx.serialization.* import kotlinx.serialization.json.JSON @Serializable data class Data(val a: Int, @Optional val b: String = "42") • Example • stringify: convert a serializable object to JSON string. JSON.stringify(Data(42)) // {"a": 42, "b": “42"} • parse: convert well formed JSON back to a data class. JSON.parse("""{"a":42}""") // Data(a=42, b="42") What is kotlinx.serialization?

Slide 7

Slide 7 text

What is kotlinx.serialization? • Annotations • @SerialName: for overriding property name with custom name. • @Optional: will be considered during serialization. But if not present, it won’t break serialization. • @Transient: will not be considered during serialization. But if present, it will cause an exception. • Nesting • are recursively serialized: enums, primitive types, arrays, lists, maps and other serializable classes.

Slide 8

Slide 8 text

@Serializable class MyData(val s: String) { @Serializer(forClass = MyData::class) companion object { override fun save(output: KOutput, obj: MyData) { output.writeStringValue(…) } override fun load(input: KInput): MyData { return MyData(…) } } } • Custom Serializer What is kotlinx.serialization?

Slide 9

Slide 9 text

• Gson vs. Moshi vs. kotlinx.serialization Performance ref: https://github.com/Kotlin/kotlinx.serialization/issues/89 ※As of March, 2018

Slide 10

Slide 10 text

• Gson vs. Moshi vs. kotlinx.serialization Which of serialization libraries? (TPO W .PTIJ W LPUMJOY TFSJBMJ[BUJPO ,PUMJO4VQQPSU ̋ ̋ 1FSGPSNBODF ˕ ̋ ̋ .FUIPE$PVOU

Slide 11

Slide 11 text

Conclusion • Kotlin / kotlinx.serialization • Kotlin Official • Supports Kotlin classes • Supports Multi-Platform (JVM & JS) …(Native) • Jake Wharton is using in SdkSearch • An Android app and Chrome Extension • Exists Retrofit2 convertor

Slide 12

Slide 12 text

Yuki Shiho @shihochan Thank you shibuta.apk #26 in 2018/06/26