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
760
今週のTopics:量子コンピュータ
ktombow
2
220
Flutter開発で便利だと感じた設定
ktombow
0
820
Other Decks in Technology
See All in Technology
全PRの83%が AIレビューだけでマージできるようになった開発組織は その後どうなったか @2026/10
athug
0
150
パスキーの自動テストはどこまでいけるのか
teamlab
PRO
0
110
Jetson Orin Nanoとk3sとローカルLLMで音声文字起こしシステム作ってみた
y_sera15
0
120
DevelopersIO 2026 知識の地図を描く ─ オントロジーとは何か?
ishikawa_satoru
1
1.5k
初対面のメンバーがチームを組み、Claude Codeでゼロからサービスをリリース
mkdev10
1
130
OptunaHub: ブラックボックス最適化のためのプラットフォーム
pfn
PRO
0
110
AIがコードを書く時代に、エンジニアは何で自分の価値を証明するのか / In an era where AI writes code how do engineers prove their value
carta_engineering
3
960
M5Stackで作る BLEマウス GPSログの世界
tomokusaba
0
290
LambdaWebFunctionsを試してみた / exploring-lambda-web-functions
koukihosaka
0
140
Rust で関数型ドメインモデリング
takonda
0
100
ai_cording_with_k8s_knowledge.pdf
mochizuki875
1
350
二歩目のフロントエンド・ウェブアクセシビリティ
camiha
2
480
Featured
See All Featured
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Balancing Empowerment & Direction
lara
6
1.3k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
350
Odyssey Design
rkendrick25
PRO
2
870
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
RailsConf 2023
tenderlove
30
1.6k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Curious Case for Waylosing
cassininazir
1
570
Git: the NoSQL Database
bkeepers
PRO
433
67k
Optimising Largest Contentful Paint
csswizardry
37
4k
Embracing the Ebb and Flow
colly
88
5.2k
Building Flexible Design Systems
yeseniaperezcruz
330
41k
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