Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kotlinx.serialization
Search
Takuji Nishibayashi
October 04, 2020
Technology
0
550
kotlinx.serialization
Takuji Nishibayashi
October 04, 2020
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
CameraX使ってみた
takuji31
0
86
kotlinx.datetime 使ってみた
takuji31
0
330
HiltのCustom Componentについて
takuji31
0
190
java.timeをAndroidで使う
takuji31
0
74
KSPを使ってコード生成
takuji31
0
310
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
990
kanmoba-returns-02.pdf
takuji31
0
180
AndroidXとKotlin Coroutines
takuji31
0
340
AndroidXに潜む便利なヤツら
takuji31
0
160
Other Decks in Technology
See All in Technology
複雑性の高いオブジェクト編集に向き合う: プラガブルなReactフォーム設計
righttouch
PRO
0
120
Amazon SageMaker Unified Studio(Preview)、Lakehouse と Amazon S3 Tables
ishikawa_satoru
0
160
WACATE2024冬セッション資料(ユーザビリティ)
scarletplover
0
210
2024年にチャレンジしたことを振り返るぞ
mitchan
0
140
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
17
14k
re:Invent 2024 Innovation Talks(NET201)で語られた大切なこと
shotashiratori
0
310
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
270
普通のエンジニアがLaravelコアチームメンバーになるまで
avosalmon
0
110
C++26 エラー性動作
faithandbrave
2
760
AWS re:Invent 2024で発表された コードを書く開発者向け機能について
maruto
0
190
小学3年生夏休みの自由研究「夏休みに Copilot で遊んでみた」
taichinakamura
0
170
Oracle Cloud Infrastructure:2024年12月度サービス・アップデート
oracle4engineer
PRO
0
200
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
BBQ
matthewcrist
85
9.4k
For a Future-Friendly Web
brad_frost
175
9.4k
Mobile First: as difficult as doing things right
swwweet
222
9k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
Thoughts on Productivity
jonyablonski
67
4.4k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
RailsConf 2023
tenderlove
29
940
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Transcript
kotlinx .serialization @takuji31 J Lang Fest Kansai Online #1
ࣗݾհ • @takuji31 • Takuji Nishibayashi • Hatena Co., Ltd.
• App Team • ίϛοΫDAYS • ΧΫϤϜ • δϟϯϓϧʔΩʔʂ
ࣗݾհ • Android • Kotlin • (Flutter / iOS /
Material Design etc.) • ! https://blog.takuji31.jp • " https://nazuna.takuji31.jp • # https://photo.takuji31.jp
ΞϓϦέʔγϣϯͰJSONYAML XMLΛಡΜͩΓॻ͍ͨΓͯ͠·͢ ͔ʁ
AGENDA • kotlinx.serializationʹ͍ͭͯ • kotlinx.serializationͷ͍ํ • ڝ߹ϥΠϒϥϦʔͱͷൺֱ
kotlinx. serializationʹ͍ͭͯ
KotlinͷγϦΞϥΠθʔγϣϯϥ ΠϒϥϦʔ
Kotlinެࣜ
ϚϧνϓϥοτϑΥʔϜରԠ
JSONҎ֎ʹෳͷϑΥʔϚοτ ʹରԠ
ϦϑϨΫγϣϯͳ͠
kaptෆཁ
Null SafetyରԠ
github.com/Kotlin/ kotlinx.serialization
kotlinx. serializationͷ͍ํ
ηοτΞοϓखॱ
plugins { kotlin("multiplatform") // or kotlin("jvm") or kotlin("android") etc. kotlin("plugin.serialization")
version "1.4.10" // Kotlin version } kotlin { sourceSets { val commonMain by getting { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2") } } } }
or github.com/Kotlin/ kotlinx.serialization#setup
JSON
{ "id": 1, "title": "సੜͨ͠ΒKotlinͩͬͨ݅", "author": "@takuji31", "stories": [ {
"id": 1001, "number": 1, "title": "ਆ༷ͷϛεͰϓϩάϥϛϯάݴޠʹసੜͨ͠" } ] }
Ϋϥεఆٛ
@Serializable data class Comic( val id: Long, val title: String,
val author: String, val stories: List<Story>, ) @Serializable data class Story( val id: Long, val number: Int, val title: String, )
γϦΞϥΠζ
val comic = Comic( id = 1L, title = "సੜͨ͠ΒKotlinͩͬͨ",
author = "@takuji31", stories = listOf( Story( id = 1001L, number = 1, title = "ਆ༷ͷϛεͰϓϩάϥϛϯάݴޠʹసੜͨ͠", ), ), ) Json.encodeToString(Comic.serializer(), comic)
val comic = Comic( id = 1L, title = "సੜͨ͠ΒKotlinͩͬͨ",
author = "@takuji31", stories = listOf( Story( id = 1001L, number = 1, title = "ਆ༷ͷϛεͰϓϩάϥϛϯάݴޠʹసੜͨ͠", ), ), ) Json.encodeToString(comic)
{"id":1,"title":"సੜͨ͠ΒKotlinͩͬͨ","author":"@takuji31","stories":[{"id":1001,"number":1,"title":"ਆ༷ͷϛεͰϓϩάϥϛϯάݴޠʹసੜͨ͠"}]}
!
val comic = Comic( ... ) val format = Json
{ prettyPrint = true } format.encodeToString(comic)
{ "id": 1, "title": "సੜͨ͠ΒKotlinͩͬͨ", "author": "@takuji31", "stories": [ {
"id": 1001, "number": 1, "title": "ਆ༷ͷϛεͰϓϩάϥϛϯάݴޠʹసੜͨ͠" } ] }
prettyPrintҎ֎ͷΦϓγϣϯ docs/json.md#json-configuration
σγϦΞϥΠζ
val json = //get json val comic: Comic = Json.decodeFromString(json)
val format = Json { ignoreUnknownKeys = true } val
json = //get json val comic: Comic = format.decodeFromString(json)
ڝ߹ϥΠϒϥϦʔ ͱͷൺֱ
ൺֱ͢ΔϥΠϒϥϦʔ • Gson • Jackson • Moshi
σγϦΞϥΠζ࣌ͷܗࣜ
ܗࣜ • ϦϑϨΫγϣϯ • kapt • GradleϓϥάΠϯ
֤ϥΠϒϥϦʔͷσγϦΞϥΠζܗࣜ ϥΠϒϥϦʔ ܗࣜ Gson ϦϑϨΫγϣϯ Jackson ϦϑϨΫγϣϯ Moshi ϦϑϨΫγϣϯ/kapt kotlinx.serialization
GradleϓϥάΠϯ
KotlinͷNull SafetyରԠ
֤ϥΠϒϥϦʔͷNull SafetyରԠ ϥΠϒϥϦʔ ରԠ/ඇରԠ Gson ඇରԠ Jackson ରԠ(jackson-module-kotlin) 1 Moshi
ରԠ kotlinx.serialization ରԠ 1 https://github.com/FasterXML/jackson-dataformats-text
JSONҎ֎ͷϑΥʔϚοτͷରԠ
֤ϥΠϒϥϦʔͷରԠϑΥʔϚοτ(Ұ෦) ϥΠϒϥϦʔ ରԠϑΥʔϚοτ Gson ͳ͠ Jackson YAML/CSV/XML/Properties/Protobuf 1 2 Moshi
ͳ͠ kotlinx.serialization YAML/XML/Properties/Protobuf 3 3 https://github.com/Kotlin/kotlinx.serialization/blob/master/formats/README.md 2 https://github.com/FasterXML/jackson-dataformats-binary 1 https://github.com/FasterXML/jackson-dataformats-text
Kotlin Multiplatform Project(KMP/ KMM)ରԠ
֤ϥΠϒϥϦʔͷରԠϑΥʔϚοτ(Ұ෦) ϥΠϒϥϦʔ ରԠ/ඇରԠ Gson ඇରԠ Jackson ඇରԠ Moshi ඇରԠ kotlinx.serialization
ରԠ
·ͱΊ
·ͱΊ • kotlinx.serializationKotlinެࣜγϦΞϥΠθʔγϣϯϥΠϒϥϦʔ • ηοτΞοϓͨ͠Β؆୯ʹ͑Δ • GradleϓϥάΠϯʹΑΔίʔυੜͳͷͰ࣮ߦ࣌/Ϗϧυ࣌ͷύϑΥʔϚϯ ε͕ྑ͍ • JSONҎ֎ʹଟͷϑΥʔϚοτʹରԠ
• ϚϧνϓϥοτϑΥʔϜରԠͰiOSαʔόʔαΠυͰ͑Δ • ϚϧνϓϥοτϑΥʔϜରԠ͍ͯ͠ͳ͍ϑΥʔϚοτ͋ΔͷͰҙ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠