All Projects → j8r → crystalizer

j8r / crystalizer

Licence: ISC License
(De)serialize any Crystal object - out of the box. Supports JSON, YAML and Byte format.

Programming Languages

crystal
512 projects

Projects that are alternatives of or similar to crystalizer

Mini Yaml
Single header YAML 1.0 C++11 serializer/deserializer.
Stars: ✭ 79 (+146.88%)
Mutual labels:  yaml, serialization
Kaml
YAML support for kotlinx.serialization
Stars: ✭ 178 (+456.25%)
Mutual labels:  yaml, serialization
Yamldotnet
YamlDotNet is a .NET library for YAML
Stars: ✭ 1,382 (+4218.75%)
Mutual labels:  yaml, serialization
dataconf
Simple dataclasses configuration management for Python with hocon/json/yaml/properties/env-vars/dict support.
Stars: ✭ 40 (+25%)
Mutual labels:  yaml, serialization
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+550%)
Mutual labels:  yaml, serialization
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+2512.5%)
Mutual labels:  yaml, serialization
Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (+253.13%)
Mutual labels:  yaml, serialization
Simple-YAML
A Java API that provides an easy-to-use way to store data using the YAML format.
Stars: ✭ 68 (+112.5%)
Mutual labels:  yaml, serialization
Chronicle Wire
A Java Serialisation Library that supports multiple formats
Stars: ✭ 204 (+537.5%)
Mutual labels:  yaml, serialization
Rapidyaml
Rapid YAML - a library to parse and emit YAML, and do it fast.
Stars: ✭ 183 (+471.88%)
Mutual labels:  yaml, serialization
Pretty Yaml
PyYAML-based module to produce pretty and readable YAML-serialized data
Stars: ✭ 110 (+243.75%)
Mutual labels:  yaml, serialization
coqpit
Simple but maybe too simple config management through python data classes. We use it for machine learning.
Stars: ✭ 67 (+109.38%)
Mutual labels:  yaml, serialization
Srsly
🦉 Modern high-performance serialization utilities for Python (JSON, MessagePack, Pickle)
Stars: ✭ 189 (+490.63%)
Mutual labels:  yaml, serialization
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (+653.13%)
Mutual labels:  yaml, serialization
tdiff
CLI tool for comparing tree like structures
Stars: ✭ 20 (-37.5%)
Mutual labels:  yaml, crystal-lang
ccxx
This is a cross-platform library software library about c, c ++, unix4, posix. Include gtest, benchmark, cmake, process lock, daemon, libuv, lua, cpython, re2, json, yaml, mysql, redis, opencv, qt, lz4, oci ... https://hub.docker.com/u/oudream
Stars: ✭ 31 (-3.12%)
Mutual labels:  yaml
cbor-d
Concise Binary Object Representation (CBOR) binary data format for D language
Stars: ✭ 20 (-37.5%)
Mutual labels:  serialization
hammerkit
build tool with support for containerization, build caching for local development and ci
Stars: ✭ 50 (+56.25%)
Mutual labels:  yaml
URSA
[DEPRECATED] integrated ECS framework for Unity
Stars: ✭ 30 (-6.25%)
Mutual labels:  serialization
yaask
Make your yaml configurable with interactive configurations!
Stars: ✭ 15 (-53.12%)
Mutual labels:  yaml

Crystalizer

CI Documentation ISC

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

Features

  • [De]serialize anything, "out-of-the-box"
  • Advanced serialization with annotations, but not required
  • Shared annotations for all formats (JSON, YAML...)

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

Installation

Add the dependency to your shard.yml:

dependencies:
  crystalizer:
    github: j8r/crystalizer

Documentation

https://j8r.github.io/crystalizer

Usage

Basic

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|
  puts format
  string = format.serialize point
  puts string
  puts format.deserialize string, to: Point
end

Result:

Crystalizer::YAML
---
x: 1
Y: a
Point(@x=1, @y="a")
Crystalizer::JSON
{
  "x": 1,
  "Y": "a"
}
Point(@x=1, @y="a")

Any

Parsing any type, and converting to JSON/YAML.

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

yaml_string = <<-E
one: 1
two: 2
sub:
  ary:
  - one
  - 2
E

yaml_any = Crystalizer::YAML.parse yaml_string
puts yaml_any

json_string = Crystalizer::JSON.serialize yaml_any
puts json_string

json_any = Crystalizer::JSON.parse json_string
puts Crystalizer::YAML.serialize json_any

Result:

{"one" => 1, "two" => 2, "sub" => {"ary" => ["one", 2]}}
{
  "one": 1,
  "two": 2,
  "sub": {
    "ary": [
      "one",
      2
    ]
  }
}
---
one: 1
two: 2
sub:
  ary:
  - one
  - 2

User-defined serialization

Allows to define custom serialization and deserialization for a given type.

struct MyType
  include Crystalizer::Type

  def initialize(@i : Int32)
  end

  def self.deserialize(deserializer : Crystalizer::Deserializer)
    new deserializer.deserialize to: Int32
  end

  def serialize(serializer : Crystalizer::Serializer) : Nil
    serializer.serialize @i
  end
end

Note

Annotations are similar to the stdlib's Serializable, but all features are not yet fully implemented.

License

Copyright (c) 2020-2022 Julien Reichardt - ISC License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].