Method: Sequel::Plugins::JsonSerializer::ClassMethods#from_json

Defined in:
lib/sequel/plugins/json_serializer.rb

#from_json(json, opts = OPTS) ⇒ Object

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



179
180
181
182
183
184
185
186
187
188
189
# File 'lib/sequel/plugins/json_serializer.rb', line 179

def from_json(json, opts=OPTS)
  v = Sequel.parse_json(json)
  case v
  when self
    v
  when Hash
    new.from_json_node(v, opts)
  else
    raise Error, "parsed json doesn't return a hash or instance of #{self}"
  end
end