Skip to content

Commit b847023

Browse files
committed
Convert Document.create* to Document.of
Now Documents are all created using Document.of, Document.ofNumber, and Document.ofObject. These methods remove the old methods like createString, createNumber, createStringMap, etc. ofNumber and ofObject are separate to avoid boxed numbers and booleans from going through them rather than of(boolean) for example.
1 parent 9cd2606 commit b847023

File tree

41 files changed

+389
-388
lines changed

Some content is hidden

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

41 files changed

+389
-388
lines changed

client-core/src/main/java/software/amazon/smithy/java/client/core/ClientTransportFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ default byte priority() {
5252
* <p>Transports must be able to be instantiated without any arguments for use in dynamic clients.
5353
*/
5454
default ClientTransport<RequestT, ResponseT> createTransport() {
55-
return createTransport(Document.createStringMap(Collections.emptyMap()));
55+
return createTransport(Document.of(Collections.emptyMap()));
5656
}
5757

5858
/**

client-core/src/test/java/software/amazon/smithy/java/client/core/ClientPipelineTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public Builder toBuilder() {
182182
})
183183
.build();
184184

185-
var response = client.call("GetSprocket", Document.createFromObject(Map.of("id", "1")));
185+
var response = client.call("GetSprocket", Document.ofObject(Map.of("id", "1")));
186186

187187
assertThat(mockQueue.remaining(), is(0));
188188
assertThat(response.getMember("id").asString(), equalTo("1"));

client-core/src/test/java/software/amazon/smithy/java/client/core/plugins/InjectIdempotencyTokenPluginTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class InjectIdempotencyTokenPluginTest {
7272

7373
@Test
7474
public void injectsToken() {
75-
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1")));
75+
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1")));
7676

7777
assertThat(token, not(nullValue()));
7878
assertThat(token.length(), greaterThan(0));
@@ -101,28 +101,28 @@ private String callAndGetToken(String operation, Document input) {
101101
.addPlugin(mock)
102102
.build();
103103

104-
client.call(operation, Document.createFromObject(input));
104+
client.call(operation, Document.of(input));
105105
assertThat(mock.getRequests(), not(empty()));
106106
return mock.getRequests().get(0).request().headers().firstValue("x-token");
107107
}
108108

109109
@Test
110110
public void doesNotInjectToken() {
111-
var token = callAndGetToken("CreateSprocketNoToken", Document.createFromObject(Map.of("id", "1")));
111+
var token = callAndGetToken("CreateSprocketNoToken", Document.ofObject(Map.of("id", "1")));
112112

113113
assertThat(token, nullValue());
114114
}
115115

116116
@Test
117117
public void usesProvidedToken() {
118-
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1", "token", "xyz")));
118+
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1", "token", "xyz")));
119119

120120
assertThat(token, equalTo("xyz"));
121121
}
122122

123123
@Test
124124
public void ignoresEmptyStringToken() {
125-
var token = callAndGetToken("CreateSprocket", Document.createFromObject(Map.of("id", "1", "token", "")));
125+
var token = callAndGetToken("CreateSprocket", Document.ofObject(Map.of("id", "1", "token", "")));
126126

127127
assertThat(token, notNullValue());
128128
assertThat(token, not(equalTo("")));

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/DefaultsTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ void setsCorrectDefault() {
4040
defaults.streamingBlob()
4141
.asByteBuffer()
4242
.thenAccept(b -> assertEquals(b, ByteBuffer.wrap(Base64.getDecoder().decode("c3RyZWFtaW5n"))));
43-
assertEquals(defaults.boolDoc(), Document.createBoolean(true));
44-
assertEquals(defaults.stringDoc(), Document.createString("string"));
45-
assertEquals(defaults.numberDoc(), Document.createInteger(1));
46-
assertEquals(defaults.floatingPointnumberDoc(), Document.createDouble(1.2));
47-
assertEquals(defaults.listDoc(), Document.createList(Collections.emptyList()));
48-
assertEquals(defaults.mapDoc(), Document.createStringMap(Collections.emptyMap()));
43+
assertEquals(defaults.boolDoc(), Document.of(true));
44+
assertEquals(defaults.stringDoc(), Document.of("string"));
45+
assertEquals(defaults.numberDoc(), Document.of(1));
46+
assertEquals(defaults.floatingPointnumberDoc(), Document.of(1.2));
47+
assertEquals(defaults.listDoc(), Document.of(Collections.emptyList()));
48+
assertEquals(defaults.mapDoc(), Document.of(Collections.emptyMap()));
4949
assertEquals(defaults.list(), List.of());
5050
assertEquals(defaults.map(), Map.of());
5151
assertEquals(defaults.timestamp(), Instant.parse("1985-04-12T23:20:50.52Z"));

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/ListsTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static Stream<SerializableShape> listTypes() {
126126
.build(),
127127
ListAllTypesInput.builder()
128128
.listOfDocuments(
129-
List.of(Document.createDouble(2.0), Document.createString("string"))
129+
List.of(Document.of(2.0), Document.of("string"))
130130
)
131131
.build()
132132
);
@@ -240,7 +240,7 @@ static Stream<SerializableShape> sparseLists() {
240240
.build(),
241241
SparseListsInput.builder()
242242
.listOfDocuments(
243-
ListUtils.of(Document.createDouble(2.0), null, Document.createString("string"))
243+
ListUtils.of(Document.of(2.0), null, Document.of("string"))
244244
)
245245
.build()
246246
);
@@ -264,8 +264,8 @@ void nullDistinctFromEmpty() {
264264
// Collections should return empty collections for access
265265
assertEquals(emptyInput.listOfBoolean(), Collections.emptyList());
266266
assertEquals(emptyInput.listOfBoolean(), nullInput.listOfBoolean());
267-
var emptyDocument = Document.createTyped(emptyInput);
268-
var nullDocument = Document.createTyped(nullInput);
267+
var emptyDocument = Document.of(emptyInput);
268+
var nullDocument = Document.of(nullInput);
269269
assertNotNull(emptyDocument.getMember("listOfBoolean"));
270270
assertNull(nullDocument.getMember("listOfBoolean"));
271271
}

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/MapsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ void nullDistinctFromEmpty() {
288288
assertEquals(emptyInput.stringBooleanMap(), Collections.emptyMap());
289289
assertEquals(emptyInput.stringBooleanMap(), nullInput.stringBooleanMap());
290290

291-
var emptyDocument = Document.createTyped(emptyInput);
292-
var nullDocument = Document.createTyped(nullInput);
291+
var emptyDocument = Document.of(emptyInput);
292+
var nullDocument = Document.of(nullInput);
293293
assertNotNull(emptyDocument.getMember("stringBooleanMap"));
294294
assertNull(nullDocument.getMember("stringBooleanMap"));
295295
}

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/RecursionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void multiplyRecursiveUnionWorks() {
114114
)
115115
)
116116
);
117-
var document = Document.createTyped(recursive);
117+
var document = Document.of(recursive);
118118
var builder = AttributeValue.builder();
119119
document.deserializeInto(builder);
120120
var output = builder.build();

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/StructuresTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class StructuresTest {
4545
static Stream<SerializableShape> memberTypes() {
4646
return Stream.of(
4747
BooleanMembersInput.builder().requiredBoolean(true).build(),
48-
DocumentMembersInput.builder().requiredDoc(Document.createString("str")).build(),
48+
DocumentMembersInput.builder().requiredDoc(Document.of("str")).build(),
4949
ListMembersInput.builder().requiredList(List.of("a", "b", "c")).build(),
5050
MapMembersInput.builder().requiredMap(Map.of("a", "b")).build(),
5151
BigDecimalMembersInput.builder().requiredBigDecimal(BigDecimal.valueOf(1.0)).build(),

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/UnionTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static Stream<SerializableShape> unionTypes() {
6060
@ParameterizedTest
6161
@MethodSource("unionTypes")
6262
void pojoToDocumentRoundTrip(UnionType pojo) {
63-
var document = Document.createTyped(pojo);
63+
var document = Document.of(pojo);
6464
var builder = UnionType.builder();
6565
document.deserializeInto(builder);
6666
var output = builder.build();
@@ -70,7 +70,7 @@ void pojoToDocumentRoundTrip(UnionType pojo) {
7070

7171
record UnknownDocument() implements Document {
7272

73-
private static final Map<String, Document> members = Map.of("UNKNOWN!!!", Document.createDouble(3.2));
73+
private static final Map<String, Document> members = Map.of("UNKNOWN!!!", Document.of(3.2));
7474

7575
@Override
7676
public ShapeType type() {
@@ -112,6 +112,6 @@ void unknownUnionDeser() {
112112
@Test
113113
void unknownUnionSerFails() {
114114
var union = UnionType.builder().$unknownMember("foo").build();
115-
assertThrows(SerializationException.class, () -> Document.createTyped(union));
115+
assertThrows(SerializationException.class, () -> Document.of(union));
116116
}
117117
}

codegen/core/src/it/java/software/amazon/smithy/java/codegen/test/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ final class Utils {
1515
private Utils() {}
1616

1717
static <T extends SerializableStruct> T pojoToDocumentRoundTrip(T pojo) {
18-
var document = Document.createTyped(pojo);
18+
var document = Document.of(pojo);
1919
ShapeBuilder<T> builder = getBuilder(pojo);
2020
document.deserializeInto(builder);
2121
return builder.build();

0 commit comments

Comments
 (0)