serializable

Version, currently main branch1 version
  • main branchlatestJan 30, 2025

github.com/jgaskins/serializable

Unified serialization interface for Crystal

3 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  serializable:
    github: jgaskins/serializable
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.13.2
License
MIT
Author
Jamie Gaskins

Dependencies

Development Dependencies

  • db*github: crystal-lang/crystal-dbdev
  • pg*github: will/crystal-pgdev
  • msgpack*github: jgaskins/msgpack-crystal, branch: serializable-unifieddev
  • serializable*path: .dev

README

Serializable

Unified serialization/deserialization interface.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      serializable:
        github: jgaskins/serializable
  2. Run shards install

Usage

In your serializable objects, include the Serializable::Object mixin:

require "serializable/object"

struct Post
  include Serializable::Object

  getter id : UUID
  getter title : String
  getter body : String
  getter author_id : UUID
  getter author_display_name : String
  getter published_at : Time
end

Make sure you require any of the adapters needed for the serialization formats you are using:

require "serializable/json"
require "serializable/msgpack"
require "serializable/db"

These adapters add the from_#{format} / to_#{format} methods. If you only need JSON, you can simply require the serializable/json adapter.

If you need additional serialization formats, please open an issue or a PR.

Development

This is still early days for this shard. The development process hasn't been ironed out yet.

Contributing

  1. Fork it (https://github.com/jgaskins/serializable/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors