Skip to content

Revert "Set explicit payload members to null if the input is empty" #6114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .changes/next-release/bugfix-AWSSDKforJavav2-e2de7f3.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.annotations.ThreadSafe;
import software.amazon.awssdk.core.SdkBytes;
Expand Down Expand Up @@ -267,11 +266,6 @@ private <T extends SdkPojo> T unmarshallFromJson(SdkPojo sdkPojo, InputStream in
return (T) unmarshallingParser.parse(sdkPojo, inputStream);
}

@SuppressWarnings("unchecked")
private <T extends SdkPojo> T unmarshallMemberFromJson(Supplier<SdkPojo> constructor, InputStream inputStream) {
return (T) unmarshallingParser.parseMember(constructor, inputStream);
}

private <TypeT extends SdkPojo> TypeT unmarshallResponse(SdkPojo sdkPojo,
SdkHttpFullResponse response) throws IOException {
JsonUnmarshallerContext context = JsonUnmarshallerContext.builder()
Expand All @@ -296,7 +290,7 @@ private <TypeT extends SdkPojo> TypeT unmarshallResponse(SdkPojo sdkPojo,
} else if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_POJO) {
Optional<AbortableInputStream> responseContent = context.response().content();
if (responseContent.isPresent()) {
field.set(sdkPojo, unmarshallMemberFromJson(field.constructor(), responseContent.get()));
field.set(sdkPojo, unmarshallFromJson(field.constructor().get(), responseContent.get()));
} else {
field.set(sdkPojo, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.annotations.ThreadSafe;
import software.amazon.awssdk.core.SdkBytes;
Expand Down Expand Up @@ -73,33 +72,6 @@ public static Builder builder() {
return new Builder();
}

/**
* Parse the provided {@link InputStream} and return the deserialized {@link SdkPojo}. Unlike
* {@link #parse(SdkPojo, InputStream)} this method returns null if the input stream is empty. This is used to unmarshall
* payload members that can be null unlike top-level response pojos.
*/
public SdkPojo parseMember(Supplier<SdkPojo> constructor, InputStream content) {
return invokeSafely(() -> {
try (JsonParser parser = jsonFactory.createParser(content)
.configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false)) {

JsonUnmarshallerContext c = JsonUnmarshallerContext.builder().build();
JsonToken token = parser.nextToken();
if (token == null) {
return null;
}
if (token == JsonToken.VALUE_NULL) {
return null;
}
if (token != JsonToken.START_OBJECT) {
throw new JsonParseException("expecting start object, got instead: " + token);
}
SdkPojo pojo = constructor.get();
return parseSdkPojo(c, pojo, parser);
}
});
}

/**
* Parse the provided {@link InputStream} and return the deserialized {@link SdkPojo}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@
}
}
},
{
"description": "Operation with explicit payload structure, with emtpy output is unmarshalled as null value",
"given": {
"response": {
"status_code": 200,
"body": ""
}
},
"when": {
"action": "unmarshall",
"operation": "OperationWithExplicitPayloadStructure"
},
"then": {
"deserializedAs": {
"PayloadMember": null
}
}
},
{
"description": "Operation with streaming payload in output is unmarshalled correctly",
"given": {
Expand Down
Loading