module JSON::Serializable
Overview
Use require "suzuri/json_serializable"
to add
#to_suzuri
, #from_suzuri
and #from_suzuri_with_timestamp
methods to all JSON::Serializable
objects.
Example usage:
require "suzuri/json_serializable"
class Person
include JSON::Serializable
@[JSON::Field(key: "name")]
property name : String
def initialize(@name)
end
end
bob = Person.new(name: "bob")
token = bob.to_suzuri(KEY)
decoded = Person.from_suzuri(token, KEY)
decoded.name # => "bob"
# Decode with ttl constraint
decoded = Person.from_suzuri(token, KEY, 5.seconds)
# Decode with timestamp
decoded, timestamp = Person.from_suzuri_with_timestamp(token, KEY)
decoded.name # => "bob"
timestamp # => Time
# Decode with timestamp and ttl constraint
decoded, timestamp = Person.from_suzuri_with_timestamp(token, KEY, 5.seconds)