software.amazon.awssdk.transfer.s3.internal.serialization.TransferManagerJsonUnmarshaller Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of s3-transfer-manager Show documentation
Show all versions of s3-transfer-manager Show documentation
The S3 Transfer Manager allows customers to easily and optimally
transfer objects and directories to and from S3.
/*
* 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.getUnmarshaller;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.traits.MapTrait;
import software.amazon.awssdk.core.traits.TraitType;
import software.amazon.awssdk.protocols.jsoncore.JsonNode;
import software.amazon.awssdk.utils.BinaryUtils;
import software.amazon.awssdk.utils.DateUtils;
/**
* Interface for unmarshalling a field from JSON.
*
* @param Type to unmarshall into.
*/
@FunctionalInterface
@SdkInternalApi
public interface TransferManagerJsonUnmarshaller {
TransferManagerJsonUnmarshaller STRING = (val, sdkField) -> val;
TransferManagerJsonUnmarshaller SHORT = (val, sdkField) -> Short.parseShort(val);
TransferManagerJsonUnmarshaller INTEGER = (val, sdkField) -> Integer.parseInt(val);
TransferManagerJsonUnmarshaller LONG = (val, sdkField) -> Long.parseLong(val);
TransferManagerJsonUnmarshaller NULL = (val, sdkField) -> null;
TransferManagerJsonUnmarshaller FLOAT = (val, sdkField) -> Float.parseFloat(val);
TransferManagerJsonUnmarshaller DOUBLE = (val, sdkField) -> Double.parseDouble(val);
TransferManagerJsonUnmarshaller BIG_DECIMAL = (val, sdkField) -> new BigDecimal(val);
TransferManagerJsonUnmarshaller BOOLEAN = (val, sdkField) -> Boolean.parseBoolean(val);
TransferManagerJsonUnmarshaller SDK_BYTES =
(content, sdkField) -> SdkBytes.fromByteArray(BinaryUtils.fromBase64(content));
TransferManagerJsonUnmarshaller INSTANT = new TransferManagerJsonUnmarshaller() {
@Override
public Instant unmarshall(String value, SdkField> field) {
if (value == null) {
return null;
}
return safeParseDate(DateUtils::parseUnixTimestampInstant).apply(value);
}
private Function safeParseDate(Function dateUnmarshaller) {
return value -> {
try {
return dateUnmarshaller.apply(value);
} catch (NumberFormatException e) {
throw SdkClientException.builder()
.message("Unable to parse date : " + value)
.cause(e)
.build();
}
};
}
};
TransferManagerJsonUnmarshaller