Skip to content

Commit f7dbe15

Browse files
authored
Update codegen service clients (#562)
1 parent 99c5c45 commit f7dbe15

44 files changed

Lines changed: 1135 additions & 984 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sdk/src/main/java/software/amazon/awssdk/iot/EnumSerializer.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,27 @@
2121
* @param <E> the enumeration type the serializer should work with
2222
*/
2323
public class EnumSerializer<E> implements JsonSerializer<E>, JsonDeserializer<E> {
24+
25+
/**
26+
* Serializes the given enum to a JsonElement
27+
* @param enumValue The enum to convert
28+
* @param typeOfEnum The enum to convert type
29+
* @param context The JsonSerializationContext to use
30+
* @return The enum as a JsonElement
31+
*/
2432
public JsonElement serialize(E enumValue, Type typeOfEnum, JsonSerializationContext context) {
2533
return new JsonPrimitive(enumValue.toString());
2634
}
2735

2836
private Method fromString;
37+
38+
/**
39+
* Deserializes the JsonElement to an enum
40+
* @param json The json to convert
41+
* @param typeOfEnum The type of enum to convert to
42+
* @param context The JsonDeserializationContext to use
43+
* @return The enum from the JsonElement data
44+
*/
2945
public E deserialize(JsonElement json, Type typeOfEnum, JsonDeserializationContext context)
3046
throws JsonParseException {
3147
if (fromString == null) {

sdk/src/main/java/software/amazon/awssdk/iot/ShadowStateFactory.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0.
4+
*/
5+
16
package software.amazon.awssdk.iot;
27

38
import software.amazon.awssdk.iot.iotshadow.model.ShadowState;
@@ -12,8 +17,14 @@
1217
import com.google.gson.stream.JsonReader;
1318
import com.google.gson.stream.JsonWriter;
1419

20+
/**
21+
* Factory class for converting ShadowStates to and from packet payloads
22+
*/
1523
public class ShadowStateFactory implements TypeAdapterFactory {
1624

25+
/**
26+
* Creates a new TypeAdapter for conversion to and from packet payloads
27+
*/
1728
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
1829

1930
Class<T> rawType = (Class<T>)type.getRawType();
@@ -24,6 +35,12 @@ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
2435
final TypeAdapter<T> delegate = gson.getDelegateAdapter(this, type);
2536

2637
return new TypeAdapter<T>() {
38+
39+
/**
40+
* Writes the type to the packet payload (JsonWriter)
41+
* @param out The JsonWriter to output the type data to
42+
* @param shadowValue The shadow value containing the data to convert
43+
*/
2744
public void write(JsonWriter out, T shadowValue) throws IOException {
2845
// Are null values present? If so, we need to process this differently
2946
ShadowState shadow = (ShadowState)shadowValue;
@@ -46,8 +63,13 @@ public void write(JsonWriter out, T shadowValue) throws IOException {
4663
delegate.write(out, shadowValue);
4764
}
4865
}
49-
public T read(JsonReader in) throws IOException {
5066

67+
/**
68+
* Reads the type from the packet payload (JsonReader)
69+
* @param in The JsonReader containing the packet payload data
70+
* @return The type created from the packet payload data
71+
*/
72+
public T read(JsonReader in) throws IOException {
5173
T returnType = delegate.read(in);
5274
return returnType;
5375
}

sdk/src/main/java/software/amazon/awssdk/iot/Timestamp.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,46 @@
1717
import java.util.Date;
1818

1919
/**
20-
* Extension of Java date class to support Json serialization. Used in IoT service models.
20+
* Extension of Java date class to support Json serialization. Used in IoT service models.
2121
*/
2222
public class Timestamp extends java.util.Date {
23+
/**
24+
* Serializer to convert Timestamp to JSON
25+
*/
2326
public static class Serializer implements JsonSerializer<Timestamp> {
27+
/**
28+
* Serializes a Timestamp to JSON
29+
* @param src The Timestamp to convert
30+
* @param typeOfSrc The Type to use
31+
* @param context The JsonSerializationContext to use
32+
* @return A JsonElement containing the Timestamp data
33+
*/
2434
public JsonElement serialize(Timestamp src, Type typeOfSrc, JsonSerializationContext context) {
2535
return new JsonPrimitive(src.getTime() / 1000); // convert from ms to seconds
2636
}
2737
}
38+
39+
/**
40+
* Deserializer to convert JSON to Timestamp
41+
*/
2842
public static class Deserializer implements JsonDeserializer<Timestamp> {
43+
/**
44+
* Deserializes JSON to a Timestamp
45+
* @param json The JsonElement containing the Timestamp
46+
* @param typeOfT The Type to use
47+
* @param context The JsonDeserializationContext to use
48+
* @return A Timestamp containing the data in the JsonElement
49+
*/
2950
public Timestamp deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
3051
throws JsonParseException {
3152
return new Timestamp(new Date(json.getAsJsonPrimitive().getAsLong() * 1000));
3253
}
3354
}
3455

56+
/**
57+
* Timestamp constructor
58+
* @param date The date to use
59+
*/
3560
public Timestamp(Date date) {
3661
super(date.getTime());
3762
}

0 commit comments

Comments
 (0)