Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
JSONEncodeで詰まった話
Search
とんとんぼ
June 04, 2023
Technology
250
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
JSONEncodeで詰まった話
JSONEncoderでnilをNullとしてエンコードした際に詰まった話と解決方法について解説しています。
とんとんぼ
June 04, 2023
More Decks by とんとんぼ
See All by とんとんぼ
Xcode27の新機能
ktombow
0
150
OSSコントリビューションの 楽しみ方と始め方
ktombow
0
64
extension 現場で使えるXcodeショートカット一覧
ktombow
0
400
Ignite の1年間の軌跡
ktombow
0
260
Swift愛好会:What's new in Xcode16 要約
ktombow
0
750
今週のTopics:量子コンピュータ
ktombow
2
220
Flutter開発で便利だと感じた設定
ktombow
0
810
Other Decks in Technology
See All in Technology
白金鉱業Meetup Vol.25 アウトカムが二値のデータに対するCausal Impact
brainpadpr
0
210
range over func 2年間の軌跡 Issue #56413 はGoのエコシステムをどう変えたか
ryujicre8ive
0
190
俺の仕事は AIに奪われないし、たぶんその BIも要らない
hikaruri
0
480
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
740
AIエージェントの自己改善をどう設計するか / How to Design Self-Improvement for AI Agents
22mi
23
15k
aws-iot-platform-architecture-use-cases.pdf
ma2shita
0
160
幾何アルゴリズムで なめらかなピン操作を / iOSDC Japan 2026 / smoothpin
kazumanagano
0
350
AI に書かせたその API、 “信頼” できますか?
nagix
0
110
Deployment の 先にある AI Agent 基盤 - kagent vNext、Agent Substrate、Hermes から読み解く Agent Runtime の現在地 / k8s-matsuri-2-ai-agent-platform-amsy810
masayaaoyama
3
570
Spring BootからQuarkusへの移行
tatsuya1bm
2
120
積み重なった技術負債への挑戦 〜初手としての全社ゴト化〜
techtekt
PRO
0
1.2k
「守り」で活用するオンデバイスLLM 〜写ってはいけないを総力戦で防ぐ〜 / iOSDC Japan 2026
nakamuuu
0
160
Featured
See All Featured
What's in a price? How to price your products and services
michaelherold
247
13k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
520
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.6k
Balancing Empowerment & Direction
lara
6
1.3k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
エンジニアに許された特別な時間の終わり
watany
109
250k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
670
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Done Done
chrislema
186
16k
Discover your Explorer Soul
emna__ayadi
2
1.3k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
A Soul's Torment
seathinner
8
3.6k
Transcript
JSONEncoderで詰まった話 5月29日(火)Swift愛好会 とんとんぼ
自己紹介 • name: とんとんぼ • iOS & Android Dev •
23卒 新卒 • 最近、アイコンを変えました→ 旧アイコン 私が描きました
アジェンダ 1. 背景 2. 本論 3. 結論
ある日の出来事・・・
None
これ頼むわ
APIの内容 { "name" : "とんとんぼ", "age" : 24, "hobby" :
"Study Swift&Kotlin" } パラメータ名 型 必須 name String ⭕ age Int ❌ hobby String ❌ パラメータ リクエスト(例)
ageとhobbyがnilの場合 はどうすればええん?
Nullでリクエストして
None
None
None
None
None
None
None
理想 現実
ここまでが背景
ちなみに
None
None
なぜ、このようなことが起きるのか?
原因の考察 • nilをNullでエンコードするオプションは自分で書くことができるから、フレー ムワークとして用意する必要がない • Nullと欠落を同一視するAPIが多い(?) • ペイロードは小さい方が良い 参考文献:[SR-9232]Optionals with
nil value do not get encoded to JSON #3594
nilをNullでエンコードしたい
nilをNullにエンコードするには
道標 • JSONEncoderがキーを保持して、Nullをセットするように設定 • 自動生成されたものは使えない • encode(to:)の実装を書く必要がある
None
None
None
このままだと不便・・・
None
None
None
None
まとめ • SwiftではAPIにリクエストを投げる際に、Int?やString?型にnilを入れても情報が欠 落する • おそらく、Kotlinも同様? • Nullと欠落を同様に扱うAPIが多いから(?) • ペイロードは小さい方が良い
解決法: • encode(to:)やプロパティラッパーで、nilをNullにエンコードするよう実装する必要が ある
None