All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.transfer.s3.internal.serialization.TransferManagerJsonMarshaller Maven / Gradle / Ivy

Go to download

The S3 Transfer Manager allows customers to easily and optimally transfer objects and directories to and from S3.

There is a newer version: 2.28.4
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 *  http://aws.amazon.com/apache2.0
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

package software.amazon.awssdk.transfer.s3.internal.serialization;

import static software.amazon.awssdk.transfer.s3.internal.serialization.TransferManagerMarshallingUtils.getMarshaller;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructMap;
import software.amazon.awssdk.protocols.core.Marshaller;
import software.amazon.awssdk.protocols.jsoncore.JsonWriter;

/**
 * Interface to marshall data according to the JSON protocol specification.
 *
 * @param  Type to marshall.
 */
@FunctionalInterface
@SdkInternalApi
public interface TransferManagerJsonMarshaller extends Marshaller {

    TransferManagerJsonMarshaller STRING = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller SHORT = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller INTEGER = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller LONG = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller FLOAT = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller DOUBLE = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller BIG_DECIMAL = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller BOOLEAN = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller INSTANT = (val, jsonGenerator) -> jsonGenerator.writeValue(val);
    TransferManagerJsonMarshaller SDK_BYTES = (val, jsonGenerator) -> jsonGenerator.writeValue(val.asByteBuffer());

    TransferManagerJsonMarshaller NULL = new TransferManagerJsonMarshaller() {
        @Override
        public void marshall(Void val, JsonWriter generator, String paramName) {
            if (paramName == null) {
                generator.writeNull();
            }
        }

        @Override
        public void marshall(Void val, JsonWriter jsonGenerator) {

        }
    };

    TransferManagerJsonMarshaller> LIST = new TransferManagerJsonMarshaller>() {
        @Override
        public void marshall(List list, JsonWriter jsonGenerator) {
            jsonGenerator.writeStartArray();
            list.forEach(val -> getMarshaller(val).marshall(val, jsonGenerator, null));
            jsonGenerator.writeEndArray();
        }

        @Override
        public boolean shouldEmit(List list) {
            return !list.isEmpty() || !(list instanceof SdkAutoConstructList);

        }
    };

    TransferManagerJsonMarshaller> MAP = new TransferManagerJsonMarshaller>() {
        @Override
        public void marshall(Map map, JsonWriter jsonGenerator) {
            jsonGenerator.writeStartObject();
            map.forEach((key, value) -> {
                if (value != null) {
                    jsonGenerator.writeFieldName(key);
                    getMarshaller(value).marshall(value, jsonGenerator, null);
                }
            });
            jsonGenerator.writeEndObject();
        }

        @Override
        public boolean shouldEmit(Map map) {
            return !map.isEmpty() || !(map instanceof SdkAutoConstructMap);

        }
    };

    default void marshall(T val, JsonWriter generator, String paramName) {
        if (!shouldEmit(val)) {
            return;
        }
        if (paramName != null) {
            generator.writeFieldName(paramName);
        }
        marshall(val, generator);
    }

    void marshall(T val, JsonWriter jsonGenerator);

    default boolean shouldEmit(T val) {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy