Module: Property::Serialization::JSON::Validator

Defined in:
lib/property/serialization/json.rb

Constant Summary collapse

NATIVE_TYPES =
[Hash, Array, Integer, Float, String, TrueClass, FalseClass, NilClass]

Class Method Summary collapse

Class Method Details

.validate(klass) ⇒ Object

Should raise an exception if the type is not serializable.



21
22
23
24
25
26
27
28
# File 'lib/property/serialization/json.rb', line 21

def self.validate(klass)
  if NATIVE_TYPES.include?(klass) ||
     (klass.respond_to?(:json_create) && klass.instance_methods.include?(:to_json))
    true
  else
    raise TypeError.new("Cannot serialize #{klass}. Missing 'self.create_json' and 'to_json' methods.")
  end
end