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)
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)
37 elsif s[0] == first_json_char
39 elsif s[0..2] == "---"
42 raise "invalid serialized data #{s[0..5].inspect}"
47 class HashSerializer < Serializer
48 def self.first_json_char
57 class ArraySerializer < Serializer
58 def self.first_json_char