microsoft_kiota_serialization_json 0.25.1 → 0.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/microsoft_kiota_serialization_json/json_parse_node_factory.rb +3 -6
- data/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb +55 -68
- data/lib/microsoft_kiota_serialization_json/json_serialization_writer_factory.rb +2 -5
- data/lib/microsoft_kiota_serialization_json/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dbf09cb43c152fe34b14248939ea8fff9bbc8006a35cceda4eee7d0692e5db8a
|
|
4
|
+
data.tar.gz: 68d268bd347d202193fb12278ec6e8e6e70bd9846b9e8dd60a64076dc3c4e01d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 03ccf61996e27134c2029e60cfc691b5fdfa0ad6aab9293ddc788e5d46965089a6c9c7af734cb906094e52fd601b238efe1190ace07e5837b2c7481f49e62e89
|
|
7
|
+
data.tar.gz: 50028e6d47369aebadb04e15393778ff5d26b7e39dbca9f2c7c53abba8efcb64511eb817793b5ef644aaf252d5da47747adbb0f3290d4e9cb4d383c8267e4b73
|
|
@@ -12,12 +12,9 @@ module MicrosoftKiotaSerializationJson
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def get_parse_node(content_type, content)
|
|
15
|
-
if
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
raise StandardError, `expected a #{get_valid_content_type} content type`
|
|
19
|
-
end
|
|
20
|
-
raise StandardError, 'content cannot be undefined or empty' unless content
|
|
15
|
+
raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.empty?
|
|
16
|
+
raise ArgumentError, "expected a #{get_valid_content_type} content type" unless get_valid_content_type.casecmp?(content_type)
|
|
17
|
+
raise ArgumentError, 'content cannot be undefined or empty' if content.nil?
|
|
21
18
|
|
|
22
19
|
JsonParseNode.new(JSON.parse(content))
|
|
23
20
|
end
|
|
@@ -23,7 +23,6 @@ module MicrosoftKiotaSerializationJson
|
|
|
23
23
|
def set_root_value(value)
|
|
24
24
|
@root_value = value
|
|
25
25
|
@has_root_value = true
|
|
26
|
-
value
|
|
27
26
|
end
|
|
28
27
|
|
|
29
28
|
def root_value?
|
|
@@ -32,98 +31,84 @@ module MicrosoftKiotaSerializationJson
|
|
|
32
31
|
|
|
33
32
|
def write_string_value(key, value)
|
|
34
33
|
raise StandardError, 'no key or value included in write_string_value(key, value)' if key.nil? && value.nil?
|
|
35
|
-
return set_root_value(value) if key.nil?
|
|
36
34
|
return if value.nil?
|
|
37
35
|
|
|
38
|
-
|
|
36
|
+
write_value(key, value)
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
def write_boolean_value(key, value)
|
|
42
40
|
raise StandardError, 'no key or value included in write_boolean_value(key, value)' if key.nil? && value.nil?
|
|
43
|
-
return set_root_value(value) if key.nil?
|
|
44
41
|
return if value.nil?
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
write_value(key, value)
|
|
47
44
|
end
|
|
48
45
|
|
|
49
46
|
def write_number_value(key, value)
|
|
50
47
|
raise StandardError, 'no key or value included in write_number_value(key, value)' if key.nil? && value.nil?
|
|
51
|
-
return set_root_value(value) if key.nil?
|
|
52
48
|
return if value.nil?
|
|
53
49
|
|
|
54
|
-
|
|
50
|
+
write_value(key, value)
|
|
55
51
|
end
|
|
56
52
|
|
|
57
53
|
def write_float_value(key, value)
|
|
58
54
|
raise StandardError, 'no key or value included in write_float_value(key, value)' if key.nil? && value.nil?
|
|
59
|
-
return set_root_value(value) if key.nil?
|
|
60
55
|
return if value.nil?
|
|
61
56
|
|
|
62
|
-
|
|
57
|
+
write_value(key, value)
|
|
63
58
|
end
|
|
64
59
|
|
|
65
60
|
def write_guid_value(key, value)
|
|
66
61
|
raise StandardError, 'no key or value included in write_guid_value(key, value)' if !key && !value
|
|
67
|
-
return set_root_value(value.to_s) unless key
|
|
68
62
|
return if value.nil?
|
|
69
63
|
|
|
70
|
-
|
|
64
|
+
write_value(key, value.to_s)
|
|
71
65
|
end
|
|
72
66
|
|
|
73
67
|
def write_date_value(key, value)
|
|
74
68
|
raise StandardError, 'no key or value included in write_date_value(key, value)' if !key && !value
|
|
75
|
-
return set_root_value(value.strftime('%Y-%m-%d')) unless key
|
|
76
69
|
return if value.nil?
|
|
77
70
|
|
|
78
|
-
|
|
71
|
+
write_value(key, value.strftime('%Y-%m-%d'))
|
|
79
72
|
end
|
|
80
73
|
|
|
81
74
|
def write_time_value(key, value)
|
|
82
75
|
raise StandardError, 'no key or value included in write_time_value(key, value)' if !key && !value
|
|
83
|
-
return set_root_value(value.strftime('%H:%M:%S%Z')) unless key
|
|
84
76
|
return if value.nil?
|
|
85
77
|
|
|
86
|
-
|
|
78
|
+
write_value(key, value.strftime('%H:%M:%S%Z'))
|
|
87
79
|
end
|
|
88
80
|
|
|
89
81
|
def write_date_time_value(key, value)
|
|
90
82
|
raise StandardError, 'no key or value included in write_date_time_value(key, value)' if !key && !value
|
|
91
|
-
return set_root_value(value.strftime('%Y-%m-%dT%H:%M:%S%Z')) unless key
|
|
92
83
|
return if value.nil?
|
|
93
84
|
|
|
94
|
-
|
|
85
|
+
write_value(key, value.strftime('%Y-%m-%dT%H:%M:%S%Z'))
|
|
95
86
|
end
|
|
96
87
|
|
|
97
88
|
def write_duration_value(key, value)
|
|
98
89
|
raise StandardError, 'no key or value included in write_duration_value(key, value)' if !key && !value
|
|
99
|
-
return set_root_value(value.string) unless key
|
|
100
90
|
return if value.nil?
|
|
101
91
|
|
|
102
|
-
|
|
92
|
+
write_value(key, value.string)
|
|
103
93
|
end
|
|
104
94
|
|
|
105
95
|
def write_byte_array_value(key, value)
|
|
106
96
|
raise StandardError, 'no key or value included in write_byte_array_value(key, value)' if key.nil? && value.nil?
|
|
107
|
-
return set_root_value([value].pack('m0')) if key.nil?
|
|
108
97
|
return if value.nil?
|
|
109
98
|
|
|
110
|
-
|
|
99
|
+
write_value(key, [value].pack('m0'))
|
|
111
100
|
end
|
|
112
101
|
|
|
113
102
|
def write_collection_of_primitive_values(key, values)
|
|
114
103
|
return unless values
|
|
115
|
-
return set_root_value(values.map { |v| serialized_scalar(v) }) unless key
|
|
116
104
|
|
|
117
|
-
|
|
118
|
-
write_any_value(key, v)
|
|
119
|
-
end
|
|
105
|
+
write_value(key, values.map { |v| serialized_scalar(v) })
|
|
120
106
|
end
|
|
121
107
|
|
|
122
108
|
def write_collection_of_object_values(key, values)
|
|
123
109
|
return unless values
|
|
124
|
-
return set_root_value(values.map { |v| object_value_hash(v) }) unless key
|
|
125
110
|
|
|
126
|
-
|
|
111
|
+
write_value(key, values.map { |v| object_value_hash(v) })
|
|
127
112
|
end
|
|
128
113
|
|
|
129
114
|
def write_object_value(key, value, *additional_values_to_merge)
|
|
@@ -138,18 +123,13 @@ module MicrosoftKiotaSerializationJson
|
|
|
138
123
|
end
|
|
139
124
|
|
|
140
125
|
def write_null_value(key)
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
@writer[key] = nil
|
|
126
|
+
write_value(key, nil)
|
|
144
127
|
end
|
|
145
128
|
|
|
146
129
|
def write_collection_of_enum_values(key, values)
|
|
147
130
|
return unless values
|
|
148
131
|
|
|
149
|
-
|
|
150
|
-
return set_root_value(serialized) unless key
|
|
151
|
-
|
|
152
|
-
@writer[key] = serialized
|
|
132
|
+
write_value(key, values.compact.map(&:to_s))
|
|
153
133
|
end
|
|
154
134
|
|
|
155
135
|
def write_enum_value(key, values)
|
|
@@ -173,6 +153,16 @@ module MicrosoftKiotaSerializationJson
|
|
|
173
153
|
|
|
174
154
|
private
|
|
175
155
|
|
|
156
|
+
# a nil key writes the document root, which a composed type wrapper of a scalar uses
|
|
157
|
+
def write_value(key, value)
|
|
158
|
+
if key.nil?
|
|
159
|
+
set_root_value(value)
|
|
160
|
+
else
|
|
161
|
+
@writer[key] = value
|
|
162
|
+
end
|
|
163
|
+
nil
|
|
164
|
+
end
|
|
165
|
+
|
|
176
166
|
def object_value_hash(value, *additional_values_to_merge)
|
|
177
167
|
temp = child_writer
|
|
178
168
|
serialize_object(value, temp)
|
|
@@ -198,46 +188,43 @@ module MicrosoftKiotaSerializationJson
|
|
|
198
188
|
end
|
|
199
189
|
end
|
|
200
190
|
|
|
191
|
+
def write_hash_value(key, value)
|
|
192
|
+
write_value(key, value.transform_values { |v| serialized_scalar(v) })
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# a composed type wrapper writes its scalar as the root value, which a nested object hash would drop
|
|
196
|
+
def write_parsable_value(key, value)
|
|
197
|
+
if key
|
|
198
|
+
write_value(key, serialized_scalar(value))
|
|
199
|
+
else
|
|
200
|
+
write_object_value(nil, value)
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
201
204
|
public
|
|
202
205
|
|
|
203
206
|
def serialized_scalar(value)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
temp
|
|
207
|
-
result = temp.write_any_value(nil, value)
|
|
208
|
-
temp.root_value? ? temp.root_value : result
|
|
207
|
+
temp = child_writer
|
|
208
|
+
temp.write_any_value(nil, value)
|
|
209
|
+
temp.root_value? ? temp.root_value : temp.writer
|
|
209
210
|
end
|
|
210
211
|
|
|
211
212
|
def write_any_value(key, value)
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
elsif value.instance_of? MicrosoftKiotaAbstractions::ISODuration
|
|
228
|
-
write_duration_value(key, value)
|
|
229
|
-
elsif value.instance_of? Array
|
|
230
|
-
write_collection_of_primitive_values(key, value)
|
|
231
|
-
elsif value.is_a? Object
|
|
232
|
-
value.to_s
|
|
233
|
-
else
|
|
234
|
-
raise StandardError, "encountered unknown value type during serialization #{value}"
|
|
235
|
-
end
|
|
236
|
-
else
|
|
237
|
-
raise StandardError, 'no key included when writing json property' unless key
|
|
238
|
-
|
|
239
|
-
@writer[key] = nil
|
|
240
|
-
|
|
213
|
+
case value
|
|
214
|
+
when nil then write_null_value(key)
|
|
215
|
+
when true, false then write_boolean_value(key, value)
|
|
216
|
+
when String, Symbol then write_string_value(key, value.to_s)
|
|
217
|
+
when Integer then write_number_value(key, value)
|
|
218
|
+
when Float then write_float_value(key, value)
|
|
219
|
+
when DateTime then write_date_time_value(key, value)
|
|
220
|
+
when Time then write_time_value(key, value)
|
|
221
|
+
when Date then write_date_value(key, value)
|
|
222
|
+
when MicrosoftKiotaAbstractions::ISODuration then write_duration_value(key, value)
|
|
223
|
+
when UUIDTools::UUID then write_guid_value(key, value)
|
|
224
|
+
when Array then write_collection_of_primitive_values(key, value)
|
|
225
|
+
when Hash then write_hash_value(key, value)
|
|
226
|
+
when MicrosoftKiotaAbstractions::Parsable then write_parsable_value(key, value)
|
|
227
|
+
else raise StandardError, "Encountered an unknown type during serialization #{value.class} with key #{key}"
|
|
241
228
|
end
|
|
242
229
|
end
|
|
243
230
|
end
|
|
@@ -11,11 +11,8 @@ module MicrosoftKiotaSerializationJson
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def get_serialization_writer(content_type)
|
|
14
|
-
if
|
|
15
|
-
|
|
16
|
-
elsif get_valid_content_type != content_type
|
|
17
|
-
raise StandardError, `expected a #{get_valid_content_type} content type`
|
|
18
|
-
end
|
|
14
|
+
raise ArgumentError, 'content type cannot be undefined or empty' if content_type.nil? || content_type.empty?
|
|
15
|
+
raise ArgumentError, "expected a #{get_valid_content_type} content type" unless get_valid_content_type.casecmp?(content_type)
|
|
19
16
|
|
|
20
17
|
JsonSerializationWriter.new
|
|
21
18
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: microsoft_kiota_serialization_json
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.25.
|
|
4
|
+
version: 0.25.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Microsoft Corporation
|
|
@@ -35,14 +35,14 @@ dependencies:
|
|
|
35
35
|
requirements:
|
|
36
36
|
- - '='
|
|
37
37
|
- !ruby/object:Gem::Version
|
|
38
|
-
version: 0.25.
|
|
38
|
+
version: 0.25.3
|
|
39
39
|
type: :runtime
|
|
40
40
|
prerelease: false
|
|
41
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
42
42
|
requirements:
|
|
43
43
|
- - '='
|
|
44
44
|
- !ruby/object:Gem::Version
|
|
45
|
-
version: 0.25.
|
|
45
|
+
version: 0.25.3
|
|
46
46
|
- !ruby/object:Gem::Dependency
|
|
47
47
|
name: uuidtools
|
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|