Module | Sequel::Plugins::JsonSerializer::ClassMethods |
In: |
lib/sequel/plugins/json_serializer.rb
|
json_serializer_opts | [R] | The default opts to use when serializing model objects to JSON. |
Attempt to parse an array of instances from the given JSON string, with options passed to InstanceMethods#from_json_node.
# File lib/sequel/plugins/json_serializer.rb, line 164 164: def array_from_json(json, opts=OPTS) 165: v = Sequel.parse_json(json) 166: if v.is_a?(Array) 167: raise(Error, 'parsed json returned an array containing non-hashes') unless v.all?{|ve| ve.is_a?(Hash) || ve.is_a?(self)} 168: v.map{|ve| ve.is_a?(self) ? ve : new.from_json_node(ve, opts)} 169: else 170: raise(Error, 'parsed json did not return an array') 171: end 172: end
Attempt to parse a single instance from the given JSON string, with options passed to InstanceMethods#from_json_node.
# File lib/sequel/plugins/json_serializer.rb, line 150 150: def from_json(json, opts=OPTS) 151: v = Sequel.parse_json(json) 152: case v 153: when self 154: v 155: when Hash 156: new.from_json_node(v, opts) 157: else 158: raise Error, "parsed json doesn't return a hash or instance of #{self}" 159: end 160: end