1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */

15
16 package software.amazon.awssdk.core.protocol;
17
18 import java.math.BigDecimal;
19 import java.time.Instant;
20 import java.util.List;
21 import java.util.Map;
22 import software.amazon.awssdk.annotations.SdkProtectedApi;
23 import software.amazon.awssdk.core.SdkBytes;
24 import software.amazon.awssdk.core.SdkPojo;
25
26 /**
27  * Represents the various types supported for marshalling.
28  *
29  * @param <T> Java type bound to the marshalling type.
30  */

31 @SdkProtectedApi
32 public interface MarshallingType<T> {
33
34     /**
35      * Used when a value is null (and thus type can't be determined).
36      */

37     MarshallingType<Void> NULL = newType(Void.class);
38
39     MarshallingType<String> STRING = newType(String.class);
40
41     MarshallingType<Integer> INTEGER = newType(Integer.class);
42
43     MarshallingType<Long> LONG = newType(Long.class);
44
45     MarshallingType<Float> FLOAT = newType(Float.class);
46
47     MarshallingType<Double> DOUBLE = newType(Double.class);
48
49     MarshallingType<BigDecimal> BIG_DECIMAL = newType(BigDecimal.class);
50
51     MarshallingType<Boolean> BOOLEAN = newType(Boolean.class);
52
53     MarshallingType<Instant> INSTANT = newType(Instant.class);
54
55     MarshallingType<SdkBytes> SDK_BYTES = newType(SdkBytes.class);
56
57     MarshallingType<SdkPojo> SDK_POJO = newType(SdkPojo.class);
58
59     MarshallingType<List<?>> LIST = newType(List.class);
60
61     MarshallingType<Map<String, ?>> MAP = newType(Map.class);
62
63     Class<? super T> getTargetClass();
64
65     static <T> MarshallingType<T> newType(Class<? super T> clzz) {
66         return new MarshallingType<T>() {
67
68             @Override
69             public Class<? super T> getTargetClass() {
70                 return clzz;
71             }
72
73             @Override
74             public String toString() {
75                 return clzz.getSimpleName();
76             }
77         };
78
79     }
80
81 }
82