Module: Restate::JsonSerde
- Defined in:
- lib/restate/serde.rb
Overview
JSON serializer/deserializer (default). Converts Ruby objects to JSON byte strings and back.
Class Method Summary collapse
-
.deserialize(buf) ⇒ Object
Deserialize a JSON byte string to a Ruby object.
-
.json_schema ⇒ Object
Return the JSON Schema for this serde, or nil if unspecified.
-
.serialize(obj) ⇒ Object
Serialize a Ruby object to a JSON byte string.
Class Method Details
.deserialize(buf) ⇒ Object
Deserialize a JSON byte string to a Ruby object. Returns nil for nil or empty input.
23 24 25 26 27 |
# File 'lib/restate/serde.rb', line 23 def deserialize(buf) return nil if buf.nil? || buf.empty? JSON.parse(buf, symbolize_names: false) end |
.json_schema ⇒ Object
Return the JSON Schema for this serde, or nil if unspecified.
30 31 32 |
# File 'lib/restate/serde.rb', line 30 def json_schema nil end |
.serialize(obj) ⇒ Object
Serialize a Ruby object to a JSON byte string. Returns empty bytes for nil.
16 17 18 19 20 |
# File 'lib/restate/serde.rb', line 16 def serialize(obj) return EMPTY_BYTES if obj.nil? JSON.generate(obj).b end |