com.ibm.cloud.objectstorage.protocol.json.internal.ValueToStringConverters Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ibm-cos-java-sdk-bundle Show documentation
Show all versions of ibm-cos-java-sdk-bundle Show documentation
A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.
/*
* Copyright 2011-2022 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.ibm.cloud.objectstorage.protocol.json.internal;
import com.ibm.cloud.objectstorage.annotation.SdkInternalApi;
import com.ibm.cloud.objectstorage.util.Base64;
import com.ibm.cloud.objectstorage.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 - 2025 Weber Informatics LLC | Privacy Policy