Jsonizer
Module to easily provide json serialization
It was structurally inspired by http://github.com/dkubb/equalizer
Installation
Using Bundler (recommended)
- Add
gem 'jsonizer'
to your Gemfile - Run
bundle install
Using rubygems
Installing from git
- Clone the repository using
git clone git://github.com/voidus/jsonizer
- Enter the directory using
cd jsonizer
- Build and install the gem with
rake install
Usage
class TransferObject
include Jsonizer.new :operation_id, :parameter
attr_reader :operation_id, :parameter
attr_accessor :calculation_strategy
def initialize operation_id, parameter, transient = "default transient attribute"
@operation_id = operation_id
@parameter = parameter
@transient_attribute = transient
end
end
TestTransferObject.new("add", [15, 20], 'transient').to_json nil
JSON.dump(TestTransferObject.new("add", [15, 20], 'transient))
# {"json_class":"TestTransferObject","operation_id":"add","parameter":[15,20]}
JSON.load(JSON.dump(TestTransferObject.new("add", [15, 20], 'transient))).inspect
JSON.dump(TestTransferObject.new("nested", TestTransferObject.new("op", "param")))
JSON.load(JSON.dump(TestTransferObject.new("nested", TestTransferObject.new("op", "param"))))
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your tests and changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request