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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
とんとんぼ
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
160
OSSコントリビューションの 楽しみ方と始め方
ktombow
0
66
extension 現場で使えるXcodeショートカット一覧
ktombow
0
420
Ignite の1年間の軌跡
ktombow
0
260
Swift愛好会:What's new in Xcode16 要約
ktombow
0
770
今週のTopics:量子コンピュータ
ktombow
2
220
Flutter開発で便利だと感じた設定
ktombow
0
830
Other Decks in Technology
See All in Technology
古い指輪から広がった JAVA コミュニティ とのつながり
yamad
0
130
フィンテック養成勉強会#68
finengine
0
160
トークン化預金DCJPYの取り組みと活用ユースケース
finengine
0
190
大型犬好きによるPugの紹介
yamanoku
1
160
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
0
310
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
140
今さら理解するウェブフォントver.2026
takanorip
3
920
実践!Cloud Run ハンズオン!! / Cloud Run handson
y0hgi
2
300
Code for Security プロジェクト紹介 2026年10月
yu23ki14
0
110
AI × アーキテクト 第1・2章|生成AIの課題とアーキテクトの素養
daidaidai
0
190
Getting Started with Google Antigravity
glaforge
0
330
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
1
360
Featured
See All Featured
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
480
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
760
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
290
Building Adaptive Systems
keathley
44
3.3k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
500
Designing for Timeless Needs
cassininazir
1
530
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.6k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
260
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