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
JSON serializers and Alba
Search
Masafumi Okura
July 22, 2020
Programming
0
680
JSON serializers and Alba
Rubyにおける各種JSONシリアライザの2020年版比較と自作のgemであるAlbaのご紹介です。
Masafumi Okura
July 22, 2020
Tweet
Share
More Decks by Masafumi Okura
See All by Masafumi Okura
Writing documentation can be fun with plugin system
okuramasafumi
0
120
Alba: Why, How and What's So Interesting
okuramasafumi
0
250
Why did my proposals get rejected?
okuramasafumi
1
540
A suggestion for the future of RDoc
okuramasafumi
1
180
15 JSON serializers for Ruby
okuramasafumi
2
240
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
53
Creating gems 101
okuramasafumi
1
100
How NOT to make your DSL terrible
okuramasafumi
0
430
オブジェクトしこう
okuramasafumi
2
340
Other Decks in Programming
See All in Programming
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
140
パスキーのすべて ── 導入・UX設計・実装の紹介 / 20250213 パスキー開発者の集い
kuralab
3
830
Lottieアニメーションをカスタマイズしてみた
tahia910
0
130
SwiftUI Viewの責務分離
elmetal
PRO
2
250
WebDriver BiDiとは何なのか
yotahada3
1
150
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
180
Introduction to kotlinx.rpc
arawn
0
740
Spring gRPC について / About Spring gRPC
mackey0225
0
230
Amazon ECS とマイクロサービスから考えるシステム構成
hiyanger
2
580
第3回 Snowflake 中部ユーザ会- dbt × Snowflake ハンズオン
hoto17296
4
380
GAEログのコスト削減
mot_techtalk
0
120
2024年のWebフロントエンドのふりかえりと2025年
sakito
3
260
Featured
See All Featured
GitHub's CSS Performance
jonrohan
1030
460k
Producing Creativity
orderedlist
PRO
344
39k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
30
4.6k
RailsConf 2023
tenderlove
29
1k
A designer walks into a library…
pauljervisheath
205
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
7k
The Language of Interfaces
destraynor
156
24k
Why You Should Never Use an ORM
jnunemaker
PRO
55
9.2k
Code Review Best Practice
trishagee
67
18k
KATA
mclloyd
29
14k
Designing Experiences People Love
moore
140
23k
How to train your dragon (web standard)
notwaldorf
91
5.8k
Transcript
RubyͷJSONγϦΞϥΠβΛ ൺֱͯ͠Έͨ2020൛ Gotanda.rb#44 2020-07-22 ©େխ࢙
ࣗݾհ • ໊લɿେխ࢙ • ॴଐɿϑϦʔϥϯεʢྺ1ͪΐͬͱɺRubyࣗମ8΄Ͳʣ • ΤσΟλɿNeovimʢVimྺ8΄Ͳʣ • ͖ͳϝιουɿinstance_exec •
झຯɿᘖᘣ☕
ࣗݾհʢଓ͖ʣ • Kaigi on RailsͷνʔϑΦʔΨφΠβʔΛ͍ͯ͠·͢ • CFPࠓ݄·ͰͳͷͰ͢ωλ͕͋Δํͥͻʂ • ʰϚελϦϯάVimʱͷ༁Λ͠·ͨ͠ •
Grow.rbͱEntaku.rbͱ͍͏ίϛϡχςΟΛιϩͰӡӦ͍ͯ͠·͢ • Shibuya.rbͱTama.rbͷڞಉΦʔΨφΠβʔͰ͋Γ·͢
ࠓͷςʔϚɿ API/JSONʹ͍ͭͯ
RubyΛͬͯJSONΛฦ͢ํ๏
JSONγϦΞϥΠβ
ϝδϟʔͲ͜ΖΛൺֱͯ͠Έͨ
JSONγϦΞϥΠβ3ܼʢେௐʣ • ActiveModelSerializersʢҎԼAMSʣ • ελʔ5kɺ • jbuilder • ελʔ3.8kɺRailsͷσϑΥϧτʹؚ·ΕΔɺ •
fast_jsonapi • ελʔ5k
ͦͷଞͷJSONγϦΞϥΠβ • jsonapi-rb • jsonapi-resources • blueprinter • jb •
representable • jsonapi-serializer
AMS • ݹࢀͷJSONγϦΞϥΠβ • Pros • ྺ࢙͕͘ɺWebʹهࣄ͕๛ʹ͋Δ • ͲΜͳJSONεΩʔϚʹରԠՄೳ •
Cons • ΄΅ϝϯς͞Ε͍ͯͳ͍༷ࢠ • ʹ͕͋Δʢಛʹfast_jsonapiͱͷൺֱͰʣ
jbuilder • Railsͷ४ެࣜJSONγϦΞϥΠβ • Pros • RailsͷίΞνʔϜʹϝϯς͞Ε͍ͯΔ҆৺ײ • RailsͰ͏ͳΒґଘؔΛ૿ͣ͞ʹࡁΉ •
Cons • ͍ɺ͔ͳΓ͍ • ه๏ʢDSLʣ͕ಠಛͰशಘ͕େม
fast_jsonapi • Netflix͕ग़ͨ͠JSON:APIಛԽܕͷJSONγϦΞϥΠβ • Pros • ඇৗʹߴ • Cons •
JSON:APIʹ४ڌͨ͠APIʹͨ͑͠ͳ͍ • Netflix͕ϝϯςΛ์غ͠ɺ༗ࢤͷϑΥʔΫ͕ଘࡏ͢Δ͕gemͷ໊લ͕ มΘ͍ͬͯͨΓͯࠞ͠ಱͱ͍ͯ͠Δ
".4 KCVJMEFS GBTU@KTPOBQJ ύϑΥʔϚϯε ͦͦ͜͜ ѱ͍ ඇৗʹྑ͍ ϝϯςφϯε ͞Ε͍ͯͳ͍ ͞Ε͍ͯΔ
͞Ε͍ͯͳ͍ ҙͷ+40/εΩʔ ϚʹରԠ͍ͯ͠Δ ͍Δ ͍Δ ͍ͳ͍
͜͜·Ͱͷ݁
• ߴ • ϝϯς͞Ε͍ͯΔ • ҙͷεΩʔϚͷJSON͕ग़ྗͰ͖ ΔʢJSON:APIܗࣜҎ֎ʹରԠ͠ ͍ͯΔʣ
ͳ͍ʁ
͓Εͷ͔Μ͕͍͖͑ͨ͞ΐ͏ ͷJSONγϦΞϥΠβɺAlba ͷ͝հ Gotanda.rb#44 2020-07-22 ©େխ࢙
• ߴ • ϝϯς͞Ε͍ͯΔ • ҙͷεΩʔϚͷJSON͕ग़ྗͰ͖ ΔʢJSON:APIܗࣜҎ֎ʹରԠ͠ ͍ͯΔʣ
ػೳΛߜΔ
ࢦ͖ͩ͢ͱࢥ͏ͷ
• ΑΓখ͞ͳίΞ • ΑΓগͳ͍DSL • ΑΓগͳ͍ґଘؔ
ΑΓখ͍͞ίΞ • ShrineʢϑΝΠϧΞοϓϩʔυϥΠϒϥϦʣRodaʢܰྔΣϒΞ ϓϦέʔγϣϯϑϨʔϜϫʔΫʣͷΑ͏ͳϓϥάΠϯϕʔεͷߏʹ ಌΕ͍ͯΔ • ࢦ͢ίΞͷResourceϞδϡʔϧΛ100ߦҎԼʹཹΊΔ͜ͱ • ֎෦͔Β֦ுՄೳʹ͍ͨ͠ •
ίΞͷϝϯςΛָʹ͍ͨ͠
ΑΓগͳ͍DSL • attribute, one, many͘Β͍Ͱे͔ͳͱࢥ͍ͬͯΔ • jbuilderͷDSL͕͔ͳΓۤखͱ͍͏ݸਓతͳؾ࣋ͪ • has_manyΛΑ͘ݟ͔͚Δ͚ͲɺRuboCopʹޡղ͞ΕͨΓ͢Δ͋͠· Γ͍͍ΞΠσΞͰͳ͍Α͏ͳ…
ΑΓগͳ͍ґଘؔ • ҙݻʹͳͬͯActiveSupportͷґଘΛՃ͍ͯ͠ͳ͍ • ͦͷ݁Ռͱͯ͠Inflection͕͑ͳͯͭ͘Β͍ • ͦͦʮΦϒδΣΫτΛJSONʹม͢Δʯ͜ͱʹґଘ͕ؔͨ͘ ͞Μඞཁͬͯ͜ͱͳ͍ͷͰɺͱ͍͏ؾ࣋ͪ • ϝϯςָ͕
• ґଘ͕ؔͳ͍gemͷಌΕ
͕࣌ؒ͋ΕιʔείʔυΛ͔ΜͨΜ ʹ͓ݟͤͰ͖Δ͔ͳ