crystalizer
Version, currently 1.1.625 versions
- 1.1.6latestFeb 13, 2023
- 1.1.5not indexedFeb 13, 2023
- 1.1.4not indexedFeb 13, 2023
- 1.1.3not indexedFeb 13, 2023
- 1.1.2not indexedFeb 13, 2023
- 1.1.1not indexedFeb 13, 2023
- 1.1.0not indexedFeb 13, 2023
- 1.0.0not indexedFeb 13, 2023
- 0.5.8not indexedFeb 13, 2023
- 0.5.7not indexedFeb 13, 2023
- 0.5.6not indexedFeb 13, 2023
- 0.5.5not indexedFeb 13, 2023
- 0.5.4not indexedFeb 13, 2023
- 0.5.3not indexedFeb 13, 2023
- 0.5.2not indexedFeb 13, 2023
- 0.5.1not indexedFeb 13, 2023
- 0.5.0not indexedFeb 13, 2023
- 0.4.2not indexedFeb 13, 2023
- 0.4.1not indexedFeb 13, 2023
- 0.4.0not indexedFeb 13, 2023
- 0.3.1not indexedFeb 13, 2023
- 0.3.0not indexedFeb 13, 2023
- 0.2.1not indexedFeb 13, 2023
- 0.2.0not indexedFeb 13, 2023
- 0.1.0not indexedFeb 13, 2023
github.com/j8r/crystalizer
(De)serialize any Crystal object, out of the box.
41 stars
0 dependents
License: ISC
Installation
# Add this to your shard.yml
dependencies:
crystalizer:
github: j8r/crystalizer
version: ~> 1.1.6Then run:
shards installshard.yml
- Crystal
>= 0.35.0, < 2.0.0- License
- ISC
- Author
- Julien Reichardt <contact@jrei.ch>
Dependencies
This version declares no dependencies.
README
# Crystalizer
[](https://github.com/j8r/crystalizer/actions?query=workflow%3ACI)
[](https://j8r.github.io/crystalizer)
[](https://en.wikipedia.org/wiki/ISC_license)
[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`:
```yaml
dependencies:
crystalizer:
github: j8r/crystalizer
```
## Documentation
https://j8r.github.io/crystalizer
## Usage
### Basic
```crystal
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.
```cr
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:
```yaml
{"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.
```crystal
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-2023 Julien Reichardt - ISC License
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
1.1.6- Tagged
- Feb 13, 2023
- Commit
857fdbb9fe6a- Crystal
>= 0.35.0, < 2.0.0- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/j8r/crystalizer
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 12, 2026
- Synced
- Aug 12, 2026
- Versions
- 25