|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +// Includes work from: |
| 7 | +/* |
| 8 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 9 | + * |
| 10 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 11 | + * You may not use this file except in compliance with the License. |
| 12 | + * A copy of the License is located at |
| 13 | + * |
| 14 | + * http://aws.amazon.com/apache2.0 |
| 15 | + * |
| 16 | + * or in the "license" file accompanying this file. This file is distributed |
| 17 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 18 | + * express or implied. See the License for the specific language governing |
| 19 | + * permissions and limitations under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +package io.opentelemetry.instrumentation.awssdk.v2_2.internal; |
| 23 | + |
| 24 | +import java.util.List; |
| 25 | +import java.util.Map; |
| 26 | +import software.amazon.awssdk.core.SdkNumber; |
| 27 | +import software.amazon.awssdk.core.document.Document; |
| 28 | +import software.amazon.awssdk.core.document.VoidDocumentVisitor; |
| 29 | +import software.amazon.awssdk.protocols.json.StructuredJsonGenerator; |
| 30 | + |
| 31 | +// Copied as-is from |
| 32 | +// https://github.com/aws/aws-sdk-java-v2/blob/7b946c1d03cbfab1252cca0b5845b18af0b2dc43/core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/marshall/DocumentTypeJsonMarshaller.java |
| 33 | +final class DocumentTypeJsonMarshaller implements VoidDocumentVisitor { |
| 34 | + |
| 35 | + private final StructuredJsonGenerator jsonGenerator; |
| 36 | + |
| 37 | + public DocumentTypeJsonMarshaller(StructuredJsonGenerator jsonGenerator) { |
| 38 | + this.jsonGenerator = jsonGenerator; |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public void visitNull() { |
| 43 | + jsonGenerator.writeNull(); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void visitBoolean(Boolean document) { |
| 48 | + jsonGenerator.writeValue(document); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void visitString(String document) { |
| 53 | + jsonGenerator.writeValue(document); |
| 54 | + } |
| 55 | + |
| 56 | + @Override |
| 57 | + public void visitNumber(SdkNumber document) { |
| 58 | + jsonGenerator.writeNumber(document.stringValue()); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public void visitMap(Map<String, Document> documentMap) { |
| 63 | + jsonGenerator.writeStartObject(); |
| 64 | + documentMap |
| 65 | + .entrySet() |
| 66 | + .forEach( |
| 67 | + entry -> { |
| 68 | + jsonGenerator.writeFieldName(entry.getKey()); |
| 69 | + entry.getValue().accept(this); |
| 70 | + }); |
| 71 | + jsonGenerator.writeEndObject(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void visitList(List<Document> documentList) { |
| 76 | + jsonGenerator.writeStartArray(); |
| 77 | + documentList.stream().forEach(document -> document.accept(this)); |
| 78 | + jsonGenerator.writeEndArray(); |
| 79 | + } |
| 80 | +} |
0 commit comments