15 JSON serializers for Ruby
by
Masafumi Okura
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
TokyuRubyձٞ15ه೦ɺ RubyͷJSONγϦΞϥΠβ 15ݸղઆ TokyuRubyձٞ15 2024-09-29 OKURA Masafumi
Slide 2
Slide 2 text
15ճ։࠵ɺ ͓ΊͰͱ͏ ͍͟͝·͢ʂʂʂ
Slide 3
Slide 3 text
15
Slide 4
Slide 4 text
15ʹؔ͢Δ ༗ӹͳΛ͠·͢
Slide 5
Slide 5 text
15
Slide 6
Slide 6 text
RubyͷJSON γϦΞϥΠβ * 15
Slide 7
Slide 7 text
self.pp • ໊લɿ͓͓͘Β·͞;Έ • ॴଐɿϑϦʔϥϯε • ՝֎׆ಈɿKaigi on RailsνʔϑΦʔΨφΠβʔɺOH! MY RUBYISTS ϙουΩϟετओ࠻ͳͲ • ͦͯ͠ɿTokyuRubyձٞ14 LTԦ
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
1. ActiveModelSeri alizers https://github.com/rails-api/active_model_serializers
Slide 10
Slide 10 text
ActiveModelSerializers • ੲ͔Β͋ΔγϦΞϥΠβ • ྑ͍ॴɿΠϯλʔωοτ্ʹͨ͘͞Μใ͕͋Δ • ྑ͍ॴɿDSL͕͍͍͢ • ѱ͍ॴɿͱͯͭͳ͍͘ • ѱ͍ॴɿΓ͍
Slide 11
Slide 11 text
૯ධɿ ࠓ࠾༻͍͔ͨ͠ͳ ͋ʁ
Slide 12
Slide 12 text
2. Blueprinter https://github.com/procore-oss/blueprinter
Slide 13
Slide 13 text
Blueprinter • ൺֱత৽͘͠ɺൺֱత༗໊ʢελʔ1000ʣ • ྑ͍ॴɿൺֱత͍ • ྑ͍ॴɿREADME͕ॆ࣮͍ͯ͠Δ • ѱ͍ॴɿಠಛͳΠϯλʔϑΣʔεʢviewͱ͍͏Έʣ • ѱ͍ॴɿϝϯςφϯε͕ඍົ
Slide 14
Slide 14 text
૯ධɿ ͜ΕΛ͓͏͔ͳͱ ࢥ͍ͬͯͨ࣌ظ͕ࢲ ʹ͋Γ·ͨ͠
Slide 15
Slide 15 text
3. jbuilder https://github.com/rails/jbuilder
Slide 16
Slide 16 text
jbuilder • RailsͷϏϡʔʹಛԽͨ͠DSL • ྑ͍ॴɿ࠷ॳ͔Βೖ͍ͬͯΔ • ྑ͍ॴɿͬ͘͞ͱJSONΛฦ͢͜ͱ͕Ͱ͖Δ • ѱ͍ॴɿύʔγϟϧ͕͍ • ѱ͍ॴɿͦͦDSL͕֮͑ΒΕͳ͍ʢ͘͠ͳ͍ʁʣ
Slide 17
Slide 17 text
૯ධɿ ͦͷDSLɺࢲ ͪΐͬͱ…
Slide 18
Slide 18 text
4. jb https://github.com/amatsuda/jb
Slide 19
Slide 19 text
jb • amatsuda wareɺRailsͷϏϡʔͰී௨ͷRuby͕ॻ͚Δ • ྑ͍ॴɿΦʔόʔϔου͕খ͍͞ • ྑ͍ॴɿRubyͦͷ··ͳͷͰֶशίετ͕খ͍͞ • ѱ͍ॴɿRubyͦͷ··ͳͷͰந͕͍
Slide 20
Slide 20 text
૯ධɿ ࣮݁ߏΘΕͯ ͍ΔͬΆ͍
Slide 21
Slide 21 text
5. jsonapi- serializer https://github.com/jsonapi-serializer/jsonapi- serializer
Slide 22
Slide 22 text
jsonapi-serializer • Net fl ix/fast_jsonapiͷϑΥʔΫ • ྑ͍ॴɿJSON:API༷ʹै͏ͳΒ͘ΘΕ͍ͯΔ • ѱ͍ॴɿJSON:API༷ʹै͍ͨ͘ͳ͍
Slide 23
Slide 23 text
૯ධɿ JSON:APIɺօ͞ ΜͲ͏Ͱ͔͢
Slide 24
Slide 24 text
6. panko_serializer https://github.com/yosiat/panko_serializer
Slide 25
Slide 25 text
panko_serializer • OjΛϕʔεʹC֦ுϝΠϯͰॻ͔ΕͨγϦΞϥΠβ • ྑ͍ॴɿ͢͞·͍͘͡ʢ࣍ͷ2ഒҎ্ߴʣ • ѱ͍ॴɿOj͕ඞਢ • ѱ͍ॴɿػೳ͋·Γଟ͘ͳ͍
Slide 26
Slide 26 text
૯ධɿ C֦ுͣΔ͍ ʢϕϯνϚʔΫతʹʣ
Slide 27
Slide 27 text
7. representable https://github.com/trailblazer/representable
Slide 28
Slide 28 text
representable • Trailblazerͱ͍͏Rails֦ுϑϨʔϜϫʔΫͷҰ෦ • ྑ͍ॴɿXMLYAMLग़ྗͰ͖Δ • ѱ͍ॴɿൺֱత • ѱ͍ॴɿJSONग़ྗʹmulti_json͕ඞཁ
Slide 29
Slide 29 text
૯ධɿ Trailblazer͖ʹ ͍͍ͷ͔ʁ
Slide 30
Slide 30 text
8. primalize https://github.com/jgaskins/primalize
Slide 31
Slide 31 text
primalize • ΦϒδΣΫτΛϓϦϛςΟϒܕʹม͢Δͱ͍͏Ξϓϩʔν • ྑ͍ॴɿܕνΣοΫ͕Ͱ͖Δ • ѱ͍ॴɿه๏͕ • ѱ͍ॴɿ͋·Γ͘ͳ͍
Slide 32
Slide 32 text
૯ධɿ ܕνΣοΫͰ͖Δ ͷྑ͍Ͱ͢Ͷ
Slide 33
Slide 33 text
9. SimpleAMS https://github.com/vasilakis fi l/SimpleAMS
Slide 34
Slide 34 text
SimpleAMS • ActiveModelSerializersͷγϯϓϧ൛…ͳͷ͔ʁ • ྑ͍ॴɿAMSΑΓߴ • ѱ͍ॴɿAMSΑΓϝϞϦফඅྔ͕ଟ͍
Slide 35
Slide 35 text
૯ධɿ γϯϓϧͱ
Slide 36
Slide 36 text
10. Rails https://github.com/rails/rails
Slide 37
Slide 37 text
Rails • ࣮Railsʹඪ४ͰγϦΞϥΠβػೳ͕ೖ͍ͬͯΔ • ྑ͍ॴɿRailsΞϓϦͳΒԿΠϯετʔϧ͠ͳͯ͘Α͍ • ྑ͍ॴɿOj.optimize_rails͢ΔͱΊͪΌ͘ͳΔ • ѱ͍ॴɿonly, except, methodsΛͬͯγϦΞϥΠζ࣌Ͱमਖ਼Ͱ͖ ͯ͠·͏ʢγϦΞϥΠβ͚ͩΛݟͯ࠷ऴग़ྗ͕Θ͔Βͳ͍ʣ
Slide 38
Slide 38 text
૯ධɿ ͍ͭ͜ɺಈͧ͘ʂ
Slide 39
Slide 39 text
11. Alba https://github.com/okuramasafumi/alba
Slide 40
Slide 40 text
Alba • ࡞ • ྑ͍ॴɿPure Rubyʹͯ͠ͱ͍ͯ • ྑ͍ॴɿײతͳDSLʹՃ͑χονͳػೳଟࡌ • ѱ͍ॴɿಛʹͳ͠
Slide 41
Slide 41 text
૯ධɿ جຊతʹ͜ΕΛ ͓͚͍͍ͬͯ
Slide 42
Slide 42 text
12. Alba ʢclasslessʣ https://github.com/okuramasafumi/alba/blob/main/ README.md#inline-de fi nition-with-albaserialize
Slide 43
Slide 43 text
Albaʢclasslessʣ • AlbaΫϥεఆ͕ٛෆཁ • ྑ͍ॴɿίϯτϩʔϥʔͷதʹγϦΞϥΠβΛॻ͖Ͱ͖Δ • ྑ͍ॴɿϒϩοΫΛ͏ͷͰɺparamsͱ͔Λ͑Δ • ѱ͍ॴɿΘͳ͍΄͏͕͍͍
Slide 44
Slide 44 text
૯ධɿ ࣮ݸਓͰϝϯς͠ ͯΔΞϓϦͰ͜Ε Λ͍ͬͯΔ
Slide 45
Slide 45 text
13. Alba ʢܕఆ͖ٛͭʣ https://github.com/okuramasafumi/alba/blob/main/ README.md#types
Slide 46
Slide 46 text
Albaʢܕఆ͖ٛͭʣ • AlbaͰܕఆ͕ٛͰ͖Δ • ྑ͍ॴɿܕఆ͕ٛͰ͖ΔʢͰ͖Δʣ • ѱ͍ॴɿ͔ͤͬ͘ܕఆٛΛͯ͠ɺTypeScriptͷܕʹӨڹ͕ͳ͍
Slide 47
Slide 47 text
૯ධɿ TypeScriptͷܕ͕ ΄͍͠ΜͰ͢ΑͶ͑
Slide 48
Slide 48 text
14. Alba ʢw/ typelizerʣ https://github.com/skryukov/typelizer
Slide 49
Slide 49 text
Alba (w/ typelizer) • AlbaͷܕఆٛγϦΞϥΠβͷఆ͔ٛΒTypeScriptͷܕ͕ಘΒΕΔ • ྑ͍ॴɿސ٬͕ຊʹཉ͔ͬͨ͠ͷ • ྑ͍ॴɿݫີͳఆٛΛॻ͔ͳͯ͋͘ΔఔܕΛ࡞ͬͯ͘ΕΔ • ѱ͍ॴɿunknown͕ଟ͘ͳΓ͕ͪ
Slide 50
Slide 50 text
૯ධɿ ଞͷਓ͕ࣗ࡞ϥΠϒ ϥϦΛ֦ுͯ͘͠Ε Δͷͱ͍͍ͯ
Slide 51
Slide 51 text
15. Alba https://github.com/okuramasafumi/alba
Slide 52
Slide 52 text
Alba • ΦνͰ͢ • ྑ͍ॴɿࣗ࡞ͳͷͰ৭ʑޠΔ͜ͱ͕͋Δ • ѱ͍ॴɿ͜ͷεϥΠυʹ༰͕ͳ͍
Slide 53
Slide 53 text
૯ධɿ ΈΜͳͬͯ͘ Εʂʂʂ
Slide 54
Slide 54 text
͝ਗ਼ௌ ͋Γ͕ͱ͏ ͍͟͝·ͨ͠ʂ