{"id":13878631,"url":"https://github.com/estepnv/fast_serializer","last_synced_at":"2025-04-28T16:11:09.484Z","repository":{"id":46107943,"uuid":"194502037","full_name":"estepnv/fast_serializer","owner":"estepnv","description":"Yet another serializer gem","archived":false,"fork":false,"pushed_at":"2022-08-10T10:42:27.000Z","size":75,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-07T09:21:07.414Z","etag":null,"topics":["activemodelserializers","api","benchmarking","fast","jruby","json","rails","ruby","serialization","serializer"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/estepnv.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-06-30T10:14:14.000Z","updated_at":"2024-10-24T11:51:52.000Z","dependencies_parsed_at":"2022-08-12T12:40:36.928Z","dependency_job_id":null,"html_url":"https://github.com/estepnv/fast_serializer","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estepnv%2Ffast_serializer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estepnv%2Ffast_serializer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estepnv%2Ffast_serializer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/estepnv%2Ffast_serializer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/estepnv","download_url":"https://codeload.github.com/estepnv/fast_serializer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251342724,"owners_count":21574245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activemodelserializers","api","benchmarking","fast","jruby","json","rails","ruby","serialization","serializer"],"created_at":"2024-08-06T08:01:55.247Z","updated_at":"2025-04-28T16:11:09.465Z","avatar_url":"https://github.com/estepnv.png","language":"Ruby","readme":"[![Gem Version](https://badge.fury.io/rb/fast_serializer_ruby.svg)](https://badge.fury.io/rb/fast_serializer_ruby)\n![Build Status](https://github.com/estepnv/fast_serializer/actions/workflows/ruby.yml/badge.svg)\n[![Maintainability](https://api.codeclimate.com/v1/badges/df7897bec85d376709bd/maintainability)](https://codeclimate.com/github/estepnv/fast_serializer/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/df7897bec85d376709bd/test_coverage)](https://codeclimate.com/github/estepnv/fast_serializer/test_coverage)\n\n# fast_serializer\n\n`fast_serializer_ruby` is a lightweight ruby object to hash transformer.\nThis library intends to solve such a typical and on the other hand important problem as efficient ruby object to hash transformation.\n\n## Performance 🚀\n- running on ruby 2.7 is **at least 6 times faster** than AMS (benchmarks was borrowed from fast_jsonapi repository)\n- running on ruby 2.7 it consumes **6 times less RAM**\n- running on jruby 9.2.7.0 **is at least 4 times faster** than AMS after warming up\n\n## Compatibility 👌\nI tried to keep the API as close as possible to active_model_serializer implementation because we all got used to it.\n\n## Features\n- conditional rendering\n- inheritence\n- included/excluded associations\n\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'fast_serializer_ruby'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install fast_serializer_ruby\n\n## Usage\n\n`fast_serializer` supports default schema definition using class methods\n\n```ruby\nclass ResourceSerializer\n  include FastSerializer::Schema::Mixin\n\n  root :resource\n\n  attributes :id, :email, :phone\n\n  attribute(:string_id, if: -\u003e { params[:stringify] }) { resource.id.to_s }\n  attribute(:float_id, unless: :stringify?) { object.id.to_f }\n  attribute(:full_name) { params[:only_first_name] ? resource.first_name : \"#{resource.first_name} #{resource.last_name}\" }\n\n  has_one :has_one_relationship, serializer: ResourceSerializer\n  has_many :has_many_relationship, serializer: ResourceSerializer\n\n  def stringify?\n    params[:stringify]\n  end\nend\n\nResourceSerializer.new(resource, meta: {foo: \"bar\"}, only_first_name: false, stringify: true, exclude: [:has_many_relationship]).serializable_hash\n=\u003e {\n     :resource =\u003e {\n       :id =\u003e 7873392581,\n       :email =\u003e \"houston@luettgen.info\",\n       :full_name =\u003e \"Jamar Graham\",\n       :phone =\u003e \"627.051.6039 x1475\",\n       :has_one_relationship =\u003e {\n         :id =\u003e 6218322696,\n         :email=\u003e\"terrellrobel@pagac.info\",\n         :full_name =\u003e \"Clay Kuphal\",\n         :phone =\u003e \"1-604-682-0732 x882\"\n       }\n     },\n     meta: { foo: \"bar\" }\n   }\n\n\n```\n\nAlso fast_serializer supports runtime schema definition\n\n```ruby\nschema = FastSerializer::Schema.new(resource)\nschema.attribute(:id)\nschema.attribute(:email)\nschema.attribute(:full_name) { |resource| \"#{resource.first_name} #{resource.last_name}\"}\nschema.attribute(:phone)\nschema.has_one(:has_one_relationship, schema: schema)\n\nschema.serializable_hash\n=\u003e {\n     :id =\u003e 7873392581,\n     :email =\u003e \"houston@luettgen.info\",\n     :full_name =\u003e \"Jamar Graham\",\n     :phone =\u003e \"627.051.6039 x1475\",\n     :has_one_relationship =\u003e {\n       :id =\u003e 6218322696,\n       :email=\u003e\"terrellrobel@pagac.info\",\n       :full_name =\u003e \"Clay Kuphal\",\n       :phone =\u003e \"1-604-682-0732 x882\"\n     }\n   }\n\n```\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/estepnv/fast_serializer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the FastSerializer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/fast_serializer/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festepnv%2Ffast_serializer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Festepnv%2Ffast_serializer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Festepnv%2Ffast_serializer/lists"}