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
540
kotlinx.serialization
Takuji Nishibayashi
October 04, 2020
Tweet
Share
More Decks by Takuji Nishibayashi
See All by Takuji Nishibayashi
CameraX使ってみた
takuji31
0
64
kotlinx.datetime 使ってみた
takuji31
0
260
HiltのCustom Componentについて
takuji31
0
150
java.timeをAndroidで使う
takuji31
0
59
KSPを使ってコード生成
takuji31
0
290
Kotlin Symbol Processing API (KSP) を使って Kotlin ア プリケーションの開発を効率化する
takuji31
1
960
kanmoba-returns-02.pdf
takuji31
0
180
AndroidXとKotlin Coroutines
takuji31
0
330
AndroidXに潜む便利なヤツら
takuji31
0
160
Other Decks in Technology
See All in Technology
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
Exadata Database Service on Dedicated Infrastructure(ExaDB-D) UI スクリーン・キャプチャ集
oracle4engineer
PRO
2
3.2k
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
28
12k
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
マルチモーダル / AI Agent / LLMOps 3つの技術トレンドで理解するLLMの今後の展望
hirosatogamo
37
12k
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
これまでの計測・開発・デプロイ方法全部見せます! / Findy ISUCON 2024-11-14
tohutohu
3
370
テストコード品質を高めるためにMutation Testingライブラリ・Strykerを実戦導入してみた話
ysknsid25
7
2.6k
スクラム成熟度セルフチェックツールを作って得た学びとその活用法
coincheck_recruit
1
140
Platform Engineering for Software Developers and Architects
syntasso
1
520
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
620
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
52
13k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
RailsConf 2023
tenderlove
29
900
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Producing Creativity
orderedlist
PRO
341
39k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
The Language of Interfaces
destraynor
154
24k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Navigating Team Friction
lara
183
14k
Automating Front-end Workflow
addyosmani
1366
200k
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αʔόʔαΠυͰ͑Δ • ϚϧνϓϥοτϑΥʔϜରԠ͍ͯ͠ͳ͍ϑΥʔϚοτ͋ΔͷͰҙ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠