Module: Property::Serialization::JSON::ClassMethods

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#validate_property_class(klass) ⇒ Object

Returns true if the given class can be serialized with JSON



12
13
14
15
16
17
18
19
# File 'lib/property/serialization/json.rb', line 12

def validate_property_class(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