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 import software.amazon.awssdk.core.document.Document;
26 
27 /**
28  * Represents the various types supported for marshalling.
29  *
30  * @param <T> Java type bound to the marshalling type.
31  */
32 @SdkProtectedApi
33 public interface MarshallingType<T> {
34 
35     /**
36      * Used when a value is null (and thus type can't be determined).
37      */
38     MarshallingType<Void> NULL = newType(Void.class);
39 
40     MarshallingType<String> STRING = newType(String.class);
41 
42     MarshallingType<Integer> INTEGER = newType(Integer.class);
43 
44     MarshallingType<Long> LONG = newType(Long.class);
45 
46     MarshallingType<Float> FLOAT = newType(Float.class);
47 
48     MarshallingType<Double> DOUBLE = newType(Double.class);
49 
50     MarshallingType<BigDecimal> BIG_DECIMAL = newType(BigDecimal.class);
51 
52     MarshallingType<Boolean> BOOLEAN = newType(Boolean.class);
53 
54     MarshallingType<Instant> INSTANT = newType(Instant.class);
55 
56     MarshallingType<SdkBytes> SDK_BYTES = newType(SdkBytes.class);
57 
58     MarshallingType<SdkPojo> SDK_POJO = newType(SdkPojo.class);
59 
60     MarshallingType<List<?>> LIST = newType(List.class);
61 
62     MarshallingType<Map<String, ?>> MAP = newType(Map.class);
63 
64     MarshallingType<Short> SHORT = newType(Short.class);
65 
66     MarshallingType<Document> DOCUMENT = newType(Document.class);
67 
getTargetClass()68     Class<? super T> getTargetClass();
69 
newType(Class<? super T> clzz)70     static <T> MarshallingType<T> newType(Class<? super T> clzz) {
71         return new MarshallingType<T>() {
72 
73             @Override
74             public Class<? super T> getTargetClass() {
75                 return clzz;
76             }
77 
78             @Override
79             public String toString() {
80                 return clzz.getSimpleName();
81             }
82         };
83 
84     }
85 
86 }
87