No commit activity in last 3 years
No release in over 3 years
Very simple framelet for serializing/deserializing objects to hashes.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
>= 0
 Project Readme

SimpleSerializer

Simple framelet for serializing/deserializing objects to hashes.

API compatible with ActiveModel::Serializer but without all the complexity and NO ROOT KEYS!

Serializer Usage

class SomeSerializer < SimpleSerializer::Serializer
  hash_attributes :id, :name, :category_id, :errors

  def category_id
    object.category.try(:id)
  end

  def errors
    ActiveModelErrorsSerializer.serialize_errors(object.errors, true) if object.errors.any?
  end
end

Use it:

SomeSerializer.serialize(object)
SomeSerializer.new(object).serialize

SomeSerializer.serialize_array([object])

Deserializer Usage

class SomeDeserializer < SimpleSerializer::Deserializer
  object_attributes :site_id, :name, :category_id, :integration_key

  def integration_key(old_integration_key)
    "XX#{@data[:other_attr]}XX#{old_integration_key}XX"
  end

  def set_site_id
    object.site_id = 99
  end
end

Use it:

SomeDeserializer.deserialize(object, data)
SomeDeserializer.new(object, data).deserialize

SomeDeserializer.deserialize_array([object1, object2, ...], [data1, data2, ...])