module Property::Serialization::JSON::Validator

Constants

NATIVE_TYPES

Public Class Methods

validate(klass) click to toggle source

Should raise an exception if the type is not serializable.

# 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