1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
8 class TypeMismatch < ArgumentError
12 if !val.is_a?(object_class)
13 raise TypeMismatch.new("cannot serialize #{val.class} as #{object_class}")
18 def self.legacy_load(s)
19 val = Psych.safe_load(s, permitted_classes: [Time])
21 # If apiserver was downgraded to a YAML-only version after
22 # storing JSON in the database, the old code would have loaded
23 # the JSON document as a plain string, and then YAML-encoded
24 # it when saving it back to the database. It's too late now to
25 # make the old code behave better, but at least we can
26 # gracefully handle the mess it leaves in the database by
27 # double-decoding on the way out.
28 return SafeJSON.load(val)
35 if s.is_a?(object_class)
36 # Rails already deserialized for us
40 elsif s[0] == first_json_char
42 elsif s[0..2] == "---"
45 raise "invalid serialized data #{s[0..5].inspect}"
50 class HashSerializer < Serializer
51 def self.first_json_char
60 class ArraySerializer < Serializer
61 def self.first_json_char