|
30 | 30 | using Amazon.Runtime.Internal.Util;
|
31 | 31 | using System.Text.Json;
|
32 | 32 | using System.Buffers;
|
| 33 | +#if !NETFRAMEWORK |
33 | 34 | using ThirdParty.RuntimeBackports;
|
34 |
| - |
| 35 | +#endif |
35 | 36 | #pragma warning disable CS0612,CS0618
|
36 | 37 | namespace Amazon.RestJsonProtocol.Model.Internal.MarshallTransformations
|
37 | 38 | {
|
@@ -70,97 +71,132 @@ public IRequest Marshall(SparseJsonMapsRequest publicRequest)
|
70 | 71 | using var memoryStream = new MemoryStream();
|
71 | 72 | using Utf8JsonWriter writer = new Utf8JsonWriter(memoryStream);
|
72 | 73 | #endif
|
| 74 | + writer.WriteStartObject(); |
| 75 | + var context = new JsonMarshallerContext(request, writer); |
| 76 | + if(publicRequest.IsSetSparseBooleanMap()) |
73 | 77 | {
|
74 |
| - writer.WriteStartObject(); |
75 |
| - var context = new JsonMarshallerContext(request, writer); |
76 |
| - if(publicRequest.IsSetSparseBooleanMap()) |
| 78 | + context.Writer.WritePropertyName("sparseBooleanMap"); |
| 79 | + context.Writer.WriteStartObject(); |
| 80 | + foreach (var publicRequestSparseBooleanMapKvp in publicRequest.SparseBooleanMap) |
77 | 81 | {
|
78 |
| - context.Writer.WritePropertyName("sparseBooleanMap"); |
79 |
| - context.Writer.WriteStartObject(); |
80 |
| - foreach (var publicRequestSparseBooleanMapKvp in publicRequest.SparseBooleanMap) |
81 |
| - { |
82 |
| - context.Writer.WritePropertyName(publicRequestSparseBooleanMapKvp.Key); |
83 |
| - var publicRequestSparseBooleanMapValue = publicRequestSparseBooleanMapKvp.Value; |
| 82 | + context.Writer.WritePropertyName(publicRequestSparseBooleanMapKvp.Key); |
| 83 | + var publicRequestSparseBooleanMapValue = publicRequestSparseBooleanMapKvp.Value; |
84 | 84 |
|
85 |
| - context.Writer.WriteBooleanValue(publicRequestSparseBooleanMapValue.Value); |
| 85 | + if (publicRequestSparseBooleanMapValue == null) |
| 86 | + { |
| 87 | + context.Writer.WriteNullValue(); |
| 88 | + } |
| 89 | + else |
| 90 | + { |
| 91 | + context.Writer.WriteBooleanValue(publicRequestSparseBooleanMapValue.Value); |
86 | 92 | }
|
87 |
| - context.Writer.WriteEndObject(); |
88 | 93 | }
|
| 94 | + context.Writer.WriteEndObject(); |
| 95 | + } |
89 | 96 |
|
90 |
| - if(publicRequest.IsSetSparseNumberMap()) |
| 97 | + if(publicRequest.IsSetSparseNumberMap()) |
| 98 | + { |
| 99 | + context.Writer.WritePropertyName("sparseNumberMap"); |
| 100 | + context.Writer.WriteStartObject(); |
| 101 | + foreach (var publicRequestSparseNumberMapKvp in publicRequest.SparseNumberMap) |
91 | 102 | {
|
92 |
| - context.Writer.WritePropertyName("sparseNumberMap"); |
93 |
| - context.Writer.WriteStartObject(); |
94 |
| - foreach (var publicRequestSparseNumberMapKvp in publicRequest.SparseNumberMap) |
95 |
| - { |
96 |
| - context.Writer.WritePropertyName(publicRequestSparseNumberMapKvp.Key); |
97 |
| - var publicRequestSparseNumberMapValue = publicRequestSparseNumberMapKvp.Value; |
| 103 | + context.Writer.WritePropertyName(publicRequestSparseNumberMapKvp.Key); |
| 104 | + var publicRequestSparseNumberMapValue = publicRequestSparseNumberMapKvp.Value; |
98 | 105 |
|
99 |
| - context.Writer.WriteNumberValue(publicRequestSparseNumberMapValue.Value); |
| 106 | + if (publicRequestSparseNumberMapValue == null) |
| 107 | + { |
| 108 | + context.Writer.WriteNullValue(); |
| 109 | + } |
| 110 | + else |
| 111 | + { |
| 112 | + context.Writer.WriteNumberValue(publicRequestSparseNumberMapValue.Value); |
100 | 113 | }
|
101 |
| - context.Writer.WriteEndObject(); |
102 | 114 | }
|
| 115 | + context.Writer.WriteEndObject(); |
| 116 | + } |
103 | 117 |
|
104 |
| - if(publicRequest.IsSetSparseSetMap()) |
| 118 | + if(publicRequest.IsSetSparseSetMap()) |
| 119 | + { |
| 120 | + context.Writer.WritePropertyName("sparseSetMap"); |
| 121 | + context.Writer.WriteStartObject(); |
| 122 | + foreach (var publicRequestSparseSetMapKvp in publicRequest.SparseSetMap) |
105 | 123 | {
|
106 |
| - context.Writer.WritePropertyName("sparseSetMap"); |
107 |
| - context.Writer.WriteStartObject(); |
108 |
| - foreach (var publicRequestSparseSetMapKvp in publicRequest.SparseSetMap) |
109 |
| - { |
110 |
| - context.Writer.WritePropertyName(publicRequestSparseSetMapKvp.Key); |
111 |
| - var publicRequestSparseSetMapValue = publicRequestSparseSetMapKvp.Value; |
| 124 | + context.Writer.WritePropertyName(publicRequestSparseSetMapKvp.Key); |
| 125 | + var publicRequestSparseSetMapValue = publicRequestSparseSetMapKvp.Value; |
112 | 126 |
|
| 127 | + if (publicRequestSparseSetMapValue == null) |
| 128 | + { |
| 129 | + context.Writer.WriteNullValue(); |
| 130 | + } |
| 131 | + else |
| 132 | + { |
113 | 133 | context.Writer.WriteStartArray();
|
114 | 134 | foreach(var publicRequestSparseSetMapValueListValue in publicRequestSparseSetMapValue)
|
115 | 135 | {
|
116 | 136 | context.Writer.WriteStringValue(publicRequestSparseSetMapValueListValue);
|
117 | 137 | }
|
118 | 138 | context.Writer.WriteEndArray();
|
119 | 139 | }
|
120 |
| - context.Writer.WriteEndObject(); |
121 | 140 | }
|
| 141 | + context.Writer.WriteEndObject(); |
| 142 | + } |
122 | 143 |
|
123 |
| - if(publicRequest.IsSetSparseStringMap()) |
| 144 | + if(publicRequest.IsSetSparseStringMap()) |
| 145 | + { |
| 146 | + context.Writer.WritePropertyName("sparseStringMap"); |
| 147 | + context.Writer.WriteStartObject(); |
| 148 | + foreach (var publicRequestSparseStringMapKvp in publicRequest.SparseStringMap) |
124 | 149 | {
|
125 |
| - context.Writer.WritePropertyName("sparseStringMap"); |
126 |
| - context.Writer.WriteStartObject(); |
127 |
| - foreach (var publicRequestSparseStringMapKvp in publicRequest.SparseStringMap) |
128 |
| - { |
129 |
| - context.Writer.WritePropertyName(publicRequestSparseStringMapKvp.Key); |
130 |
| - var publicRequestSparseStringMapValue = publicRequestSparseStringMapKvp.Value; |
| 150 | + context.Writer.WritePropertyName(publicRequestSparseStringMapKvp.Key); |
| 151 | + var publicRequestSparseStringMapValue = publicRequestSparseStringMapKvp.Value; |
131 | 152 |
|
| 153 | + if (publicRequestSparseStringMapValue == null) |
| 154 | + { |
| 155 | + context.Writer.WriteNullValue(); |
| 156 | + } |
| 157 | + else |
| 158 | + { |
132 | 159 | context.Writer.WriteStringValue(publicRequestSparseStringMapValue);
|
133 | 160 | }
|
134 |
| - context.Writer.WriteEndObject(); |
135 | 161 | }
|
| 162 | + context.Writer.WriteEndObject(); |
| 163 | + } |
136 | 164 |
|
137 |
| - if(publicRequest.IsSetSparseStructMap()) |
| 165 | + if(publicRequest.IsSetSparseStructMap()) |
| 166 | + { |
| 167 | + context.Writer.WritePropertyName("sparseStructMap"); |
| 168 | + context.Writer.WriteStartObject(); |
| 169 | + foreach (var publicRequestSparseStructMapKvp in publicRequest.SparseStructMap) |
138 | 170 | {
|
139 |
| - context.Writer.WritePropertyName("sparseStructMap"); |
140 |
| - context.Writer.WriteStartObject(); |
141 |
| - foreach (var publicRequestSparseStructMapKvp in publicRequest.SparseStructMap) |
142 |
| - { |
143 |
| - context.Writer.WritePropertyName(publicRequestSparseStructMapKvp.Key); |
144 |
| - var publicRequestSparseStructMapValue = publicRequestSparseStructMapKvp.Value; |
| 171 | + context.Writer.WritePropertyName(publicRequestSparseStructMapKvp.Key); |
| 172 | + var publicRequestSparseStructMapValue = publicRequestSparseStructMapKvp.Value; |
145 | 173 |
|
| 174 | + if (publicRequestSparseStructMapValue == null) |
| 175 | + { |
| 176 | + context.Writer.WriteNullValue(); |
| 177 | + } |
| 178 | + else |
| 179 | + { |
146 | 180 | context.Writer.WriteStartObject();
|
147 | 181 |
|
148 | 182 | var marshaller = GreetingStructMarshaller.Instance;
|
149 | 183 | marshaller.Marshall(publicRequestSparseStructMapValue, context);
|
150 | 184 |
|
151 | 185 | context.Writer.WriteEndObject();
|
152 | 186 | }
|
153 |
| - context.Writer.WriteEndObject(); |
154 | 187 | }
|
| 188 | + context.Writer.WriteEndObject(); |
| 189 | + } |
155 | 190 |
|
156 |
| - writer.WriteEndObject(); |
157 |
| - writer.Flush(); |
| 191 | + writer.WriteEndObject(); |
| 192 | + writer.Flush(); |
| 193 | + // ToArray() must be called here because aspects of sigv4 signing require a byte array |
158 | 194 | #if !NETFRAMEWORK
|
159 |
| - request.Content = arrayPoolBufferWriter.WrittenMemory.ToArray(); |
| 195 | + request.Content = arrayPoolBufferWriter.WrittenMemory.ToArray(); |
160 | 196 | #else
|
161 |
| - request.Content = memoryStream.ToArray(); |
| 197 | + request.Content = memoryStream.ToArray(); |
162 | 198 | #endif
|
163 |
| - } |
| 199 | + |
164 | 200 |
|
165 | 201 |
|
166 | 202 | return request;
|
|
0 commit comments