Module: Codecs::DataClassCodec
- Defined in:
- lib/emery/codecs.rb
Class Method Summary collapse
- .applicable?(type) ⇒ Boolean
- .deserialize(type, json_value) ⇒ Object
- .serialize(type, value) ⇒ Object
Class Method Details
.applicable?(type) ⇒ Boolean
191 192 193 |
# File 'lib/emery/codecs.rb', line 191 def self.applicable?(type) type.respond_to? :ancestors and type.ancestors.include? DataClass end |
.deserialize(type, json_value) ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/emery/codecs.rb', line 194 def self.deserialize(type, json_value) T.check(T.hash(String, NilableUnknown), json_value) parameters = type.typed_attributes.map do |attr, attr_type| attr_value = json_value[attr.to_s] [attr, Jsoner.deserialize(attr_type, attr_value)] end return type.new(parameters.to_h) end |