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

com.amazonaws.protocol.json.internal.ValueToStringConverters 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.internal;

import com.amazonaws.annotation.SdkInternalApi;
import com.amazonaws.util.Base64;
import com.amazonaws.util.StringUtils;
import java.nio.charset.Charset;
import java.util.Date;

/**
 * Converts various types to Strings. Used for Query Param/Header/Path marshalling.
 */
@SdkInternalApi
public class ValueToStringConverters {

    /**
     * Simple interface to convert a type to a String.
     *
     * @param  Type to convert.
     */
    public interface ValueToString {
        String convert(T val);
    }

    /**
     * Identity converter.
     */
    public static final ValueToString FROM_STRING = new ValueToString() {
        @Override
        public String convert(String val) {
            return val;
        }
    };

    public static final ValueToString FROM_INTEGER = new ValueToString() {
        @Override
        public String convert(Integer val) {
            return StringUtils.fromInteger(val);
        }
    };

    public static final ValueToString FROM_LONG = new ValueToString() {
        @Override
        public String convert(Long val) {
            return StringUtils.fromLong(val);
        }
    };

    public static final ValueToString FROM_SHORT = new ValueToString() {
        @Override
        public String convert(Short val) {
            return StringUtils.fromShort(val);
        }
    };


    public static final ValueToString FROM_FLOAT = new ValueToString() {
        @Override
        public String convert(Float val) {
            return StringUtils.fromFloat(val);
        }
    };

    public static final ValueToString FROM_DOUBLE = new ValueToString() {
        @Override
        public String convert(Double val) {
            return StringUtils.fromDouble(val);
        }
    };

    /**
     * Marshalls boolean as a literal 'true' or 'false' string.
     */
    public static final ValueToString FROM_BOOLEAN = new ValueToString() {
        @Override
        public String convert(Boolean val) {
            return StringUtils.fromBoolean(val);
        }
    };

    /**
     * Marshalls date to an ISO8601 date string.
     */
    public static final ValueToString FROM_DATE = new ValueToString() {
        @Override
        public String convert(Date val) {
            return StringUtils.fromDate(val);
        }
    };

    /**
     * Converter for JSON value headers. JSON value headers are base-64 encoded.
     */
    public static final ValueToString FROM_JSON_VALUE_HEADER = new ValueToString() {
        @Override
        public String convert(String val) {
            return Base64.encodeAsString(val.getBytes(Charset.forName("utf-8")));
        }
    };
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy