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

com.amazonaws.protocol.json.JsonProtocolMarshallerBuilder Maven / Gradle / Ivy

Go to download

The AWS SDK for Java - Core module holds the classes that are used by the individual service clients to interact with Amazon Web Services. Users need to depend on aws-java-sdk artifact for accessing individual client classes.

There is a newer version: 1.12.778
Show newest version
/*
 * Copyright 2011-2024 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 com.amazonaws.protocol.json;

import com.amazonaws.annotation.SdkProtectedApi;
import com.amazonaws.protocol.MarshallLocation;
import com.amazonaws.protocol.MarshallingType;
import com.amazonaws.protocol.OperationInfo;
import com.amazonaws.protocol.ProtocolMarshaller;
import com.amazonaws.protocol.ProtocolRequestMarshaller;
import com.amazonaws.protocol.json.internal.EmptyBodyJsonMarshaller;
import com.amazonaws.protocol.json.internal.JsonProtocolMarshaller;
import com.amazonaws.protocol.json.internal.MarshallerRegistry;
import com.amazonaws.protocol.json.internal.SimpleTypeJsonMarshallers;

/**
 * Builder to create an appropriate implementation of {@link ProtocolMarshaller} for JSON based services.
 *
 * @param  Type of the original request object.
 */
@SdkProtectedApi
public class JsonProtocolMarshallerBuilder {

    private StructuredJsonGenerator jsonGenerator;
    private String contentType;
    private OperationInfo operationInfo;
    private T originalRequest;
    private MarshallerRegistry.Builder marshallerRegistry;
    private EmptyBodyJsonMarshaller emptyBodyMarshaller;

    public static  JsonProtocolMarshallerBuilder standard() {
        return new JsonProtocolMarshallerBuilder();
    }

    public JsonProtocolMarshallerBuilder jsonGenerator(StructuredJsonGenerator jsonGenerator) {
        this.jsonGenerator = jsonGenerator;
        return this;
    }

    public JsonProtocolMarshallerBuilder contentType(String contentType) {
        this.contentType = contentType;
        return this;
    }

    public JsonProtocolMarshallerBuilder operationInfo(OperationInfo operationInfo) {
        this.operationInfo = operationInfo;
        return this;
    }

    public JsonProtocolMarshallerBuilder originalRequest(T originalRequest) {
        this.originalRequest = originalRequest;
        return this;
    }

    /**
     * Has been used to direct whether an explicit JSON null should be sent as the body when the payload member is null,
     * but now does nothing. Deprecated in favor of directly supplying a marshaller for empty bodies.
     *
     * @see #emptyBodyMarshaller(EmptyBodyJsonMarshaller)
     */
    @Deprecated
    public JsonProtocolMarshallerBuilder sendExplicitNullForPayload(boolean sendExplicitNullForPayload) {
        return this;
    }

    /**
     * Sets the marshaller to use when a request contains an explicit member but that member is null.
     *
     * @param emptyBodyMarshaller An empty body marshaller
     * @return This builder for method chaining
     */
    public JsonProtocolMarshallerBuilder emptyBodyMarshaller(EmptyBodyJsonMarshaller emptyBodyMarshaller) {
        this.emptyBodyMarshaller = emptyBodyMarshaller;
        return this;
    }

    /**
     * Registers an override for the marshaller registry.
     *
     * @param marshallLocation Location to override marshaller for.
     * @param marshallingType  Type to override marshaller for.
     * @param marshaller       Marshaller to use for the given location and type.
     * @param       Type of thing being marshalled.
     * @return This builder for method chaining.
     */
    public  JsonProtocolMarshallerBuilder marshallerOverride(MarshallLocation marshallLocation,
                                                                           MarshallingType marshallingType,
                                                                           StructuredJsonMarshaller marshaller) {
        if (marshallerRegistry == null) {
            this.marshallerRegistry = MarshallerRegistry.builder();
        }
        marshallerRegistry.addMarshaller(marshallLocation, marshallingType, SimpleTypeJsonMarshallers.adapt(marshaller));
        return this;
    }

    public ProtocolRequestMarshaller build() {
        return new JsonProtocolMarshaller(jsonGenerator,
                                             contentType,
                                             operationInfo,
                                             originalRequest,
                                             marshallerRegistry,
                                             emptyBodyMarshaller);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy