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
660
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
Why did my proposals get rejected?
okuramasafumi
1
440
A suggestion for the future of RDoc
okuramasafumi
1
66
15 JSON serializers for Ruby
okuramasafumi
2
110
Tech Events, Should We See Them from the Outside or the Inside?
okuramasafumi
1
39
Creating gems 101
okuramasafumi
1
82
How NOT to make your DSL terrible
okuramasafumi
0
280
オブジェクトしこう
okuramasafumi
2
210
Debugging Alba
okuramasafumi
1
190
Learning Ruby
okuramasafumi
5
560
Other Decks in Programming
See All in Programming
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
200
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Jakarta EE meets AI
ivargrimstad
0
600
CSC509 Lecture 11
javiergs
PRO
0
180
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
Amazon Qを使ってIaCを触ろう!
maruto
0
400
役立つログに取り組もう
irof
28
9.6k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
Realtime API 入門
riofujimon
0
150
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
タクシーアプリ『GO』のリアルタイムデータ分析基盤における機械学習サービスの活用
mot_techtalk
4
1.4k
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Why Our Code Smells
bkeepers
PRO
334
57k
Building an army of robots
kneath
302
43k
Faster Mobile Websites
deanohume
305
30k
How to Ace a Technical Interview
jacobian
276
23k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
Building Applications with DynamoDB
mza
90
6.1k
What's new in Ruby 2.0
geeforr
343
31k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
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ͷಌΕ
͕࣌ؒ͋ΕιʔείʔυΛ͔ΜͨΜ ʹ͓ݟͤͰ͖Δ͔ͳ