Crystalizer

Build Status ISC

[De]serialize any Crystal object - out of the box. Supports JSON, YAML.

Features

Implementation bonus: no monkey patching involved :) (no method pollution on objects)

Installation

Add the dependency to your shard.yml:

dependencies:
  clicr:
    github: j8r/crystalizer

Usage

require "crystalizer/json"
require "crystalizer/yaml"


struct Point
  getter x : Int32
  @[Crystalizer::Field(key: "Y")]
  getter y : String

  def initialize(@x, @y)
  end
end

point = Point.new 1, "a"

{Crystalizer::YAML, Crystalizer::JSON}.each do |format|
  string = format.serialize point
  puts string
  puts format.deserialize string, to: Point
end

Note: annotations are similar to the stdlib's Serializable, but all features are yet fully implemented.

License

Copyright (c) 2020 Julien Reichardt - ISC License