Skip to content

Commit 90c3534

Browse files
authored
Revert "Set explicit payload members to null if the input is empty (#6111)"
This reverts commit 3ec934d.
1 parent 3ec934d commit 90c3534

File tree

4 files changed

+1
-59
lines changed

4 files changed

+1
-59
lines changed

.changes/next-release/bugfix-AWSSDKforJavav2-e2de7f3.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/unmarshall/JsonProtocolUnmarshaller.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Optional;
30-
import java.util.function.Supplier;
3130
import software.amazon.awssdk.annotations.SdkInternalApi;
3231
import software.amazon.awssdk.annotations.ThreadSafe;
3332
import software.amazon.awssdk.core.SdkBytes;
@@ -267,11 +266,6 @@ private <T extends SdkPojo> T unmarshallFromJson(SdkPojo sdkPojo, InputStream in
267266
return (T) unmarshallingParser.parse(sdkPojo, inputStream);
268267
}
269268

270-
@SuppressWarnings("unchecked")
271-
private <T extends SdkPojo> T unmarshallMemberFromJson(Supplier<SdkPojo> constructor, InputStream inputStream) {
272-
return (T) unmarshallingParser.parseMember(constructor, inputStream);
273-
}
274-
275269
private <TypeT extends SdkPojo> TypeT unmarshallResponse(SdkPojo sdkPojo,
276270
SdkHttpFullResponse response) throws IOException {
277271
JsonUnmarshallerContext context = JsonUnmarshallerContext.builder()
@@ -296,7 +290,7 @@ private <TypeT extends SdkPojo> TypeT unmarshallResponse(SdkPojo sdkPojo,
296290
} else if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_POJO) {
297291
Optional<AbortableInputStream> responseContent = context.response().content();
298292
if (responseContent.isPresent()) {
299-
field.set(sdkPojo, unmarshallMemberFromJson(field.constructor(), responseContent.get()));
293+
field.set(sdkPojo, unmarshallFromJson(field.constructor().get(), responseContent.get()));
300294
} else {
301295
field.set(sdkPojo, null);
302296
}

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/unmarshall/JsonUnmarshallingParser.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.util.LinkedHashMap;
2525
import java.util.List;
2626
import java.util.Map;
27-
import java.util.function.Supplier;
2827
import software.amazon.awssdk.annotations.SdkInternalApi;
2928
import software.amazon.awssdk.annotations.ThreadSafe;
3029
import software.amazon.awssdk.core.SdkBytes;
@@ -73,33 +72,6 @@ public static Builder builder() {
7372
return new Builder();
7473
}
7574

76-
/**
77-
* Parse the provided {@link InputStream} and return the deserialized {@link SdkPojo}. Unlike
78-
* {@link #parse(SdkPojo, InputStream)} this method returns null if the input stream is empty. This is used to unmarshall
79-
* payload members that can be null unlike top-level response pojos.
80-
*/
81-
public SdkPojo parseMember(Supplier<SdkPojo> constructor, InputStream content) {
82-
return invokeSafely(() -> {
83-
try (JsonParser parser = jsonFactory.createParser(content)
84-
.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false)) {
85-
86-
JsonUnmarshallerContext c = JsonUnmarshallerContext.builder().build();
87-
JsonToken token = parser.nextToken();
88-
if (token == null) {
89-
return null;
90-
}
91-
if (token == JsonToken.VALUE_NULL) {
92-
return null;
93-
}
94-
if (token != JsonToken.START_OBJECT) {
95-
throw new JsonParseException("expecting start object, got instead: " + token);
96-
}
97-
SdkPojo pojo = constructor.get();
98-
return parseSdkPojo(c, pojo, parser);
99-
}
100-
});
101-
}
102-
10375
/**
10476
* Parse the provided {@link InputStream} and return the deserialized {@link SdkPojo}.
10577
*/

test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases/rest-json-output.json

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@
1919
}
2020
}
2121
},
22-
{
23-
"description": "Operation with explicit payload structure, with emtpy output is unmarshalled as null value",
24-
"given": {
25-
"response": {
26-
"status_code": 200,
27-
"body": ""
28-
}
29-
},
30-
"when": {
31-
"action": "unmarshall",
32-
"operation": "OperationWithExplicitPayloadStructure"
33-
},
34-
"then": {
35-
"deserializedAs": {
36-
"PayloadMember": null
37-
}
38-
}
39-
},
4022
{
4123
"description": "Operation with streaming payload in output is unmarshalled correctly",
4224
"given": {

0 commit comments

Comments
 (0)