Module Sequel::Plugins::JsonSerializer::ClassMethods
In: lib/sequel/plugins/json_serializer.rb

Methods

Attributes

json_serializer_opts  [R]  The default opts to use when serializing model objects to JSON.

Public Instance methods

Attempt to parse an array of instances from the given JSON string, with options passed to InstanceMethods#from_json_node.

[Source]

     # File lib/sequel/plugins/json_serializer.rb, line 156
156:         def array_from_json(json, opts=OPTS)
157:           v = Sequel.parse_json(json)
158:           if v.is_a?(Array)
159:             raise(Error, 'parsed json returned an array containing non-hashes') unless v.all?{|ve| ve.is_a?(Hash) || ve.is_a?(self)}
160:             v.map{|ve| ve.is_a?(self) ? ve : new.from_json_node(ve, opts)}
161:           else
162:             raise(Error, 'parsed json did not return an array')
163:           end
164:         end

Attempt to parse a single instance from the given JSON string, with options passed to InstanceMethods#from_json_node.

[Source]

     # File lib/sequel/plugins/json_serializer.rb, line 142
142:         def from_json(json, opts=OPTS)
143:           v = Sequel.parse_json(json)
144:           case v
145:           when self
146:             v
147:           when Hash
148:             new.from_json_node(v, opts)
149:           else
150:             raise Error, "parsed json doesn't return a hash or instance of #{self}"
151:           end
152:         end

[Validate]