Skip to content

Fixed the behavior of REST-XML and REST-JSON services that respond with no payload. #2064

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

Merged
merged 1 commit into from
Sep 23, 2020
Merged
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
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-985054b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"description": "Fixed an issue where successful JSON service responses were required to include a payload (fixes NullPointerException originating from JsonProtocolUnmarshaller)."
}
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavav2-9917e4a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"description": "Fixed an issue with XML services, where the service responding with no payload would treat the payload as empty. Now, empty payloads will properly be populated within the XML response as \"null\"."
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ public T unmarshall(JsonUnmarshallerContext context,

public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo,
SdkHttpFullResponse response) throws IOException {
if (hasPayloadMembersOnUnmarshall(sdkPojo) && !hasExplicitBlobPayloadMember(sdkPojo)) {
SdkJsonNode jsonNode = parser.parse(ReleasableInputStream.wrap(response.content().orElse(null)).disableClose());
if (hasPayloadMembersOnUnmarshall(sdkPojo) && !hasExplicitBlobPayloadMember(sdkPojo) && response.content().isPresent()) {
SdkJsonNode jsonNode = parser.parse(ReleasableInputStream.wrap(response.content().get()).disableClose());
return unmarshall(sdkPojo, response, jsonNode);
} else {
return unmarshall(sdkPojo, response, null);
Expand Down Expand Up @@ -204,8 +204,9 @@ private static <TypeT extends SdkPojo> TypeT unmarshallStructured(SdkPojo sdkPoj
SdkJsonNode jsonContent,
JsonUnmarshallerContext context) {
for (SdkField<?> field : sdkPojo.sdkFields()) {
if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_BYTES) {
field.set(sdkPojo, SdkBytes.fromInputStream(context.response().content().orElse(null)));
if (isExplicitPayloadMember(field) && field.marshallingType() == MarshallingType.SDK_BYTES &&
context.response().content().isPresent()) {
field.set(sdkPojo, SdkBytes.fromInputStream(context.response().content().get()));
} else {
SdkJsonNode jsonFieldContent = getSdkJsonNode(jsonContent, field);
JsonUnmarshaller<Object> unmarshaller = context.getUnmarshaller(field.location(), field.marshallingType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static XmlProtocolUnmarshaller create() {

public <TypeT extends SdkPojo> TypeT unmarshall(SdkPojo sdkPojo,
SdkHttpFullResponse response) {

XmlElement document = XmlResponseParserUtils.parse(sdkPojo, response);
return unmarshall(sdkPojo, document, response);
}
Expand All @@ -81,6 +80,11 @@ SdkPojo unmarshall(XmlUnmarshallerContext context, SdkPojo sdkPojo, XmlElement r
XmlUnmarshaller<Object> unmarshaller = REGISTRY.getUnmarshaller(field.location(), field.marshallingType());

if (root != null && field.location() == MarshallLocation.PAYLOAD) {
if (!context.response().content().isPresent()) {
// This is a payload field, but the service sent no content. Do not populate this field (leave it null).
continue;
}

if (isAttribute(field)) {
root.getOptionalAttributeByName(field.unmarshallLocationName())
.ifPresent(e -> field.set(sdkPojo, e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,39 @@
// Empty object
}
}
},
{
"description": "Empty payload responses are unmarshalled",
"given": {
"response": {
"status_code": 204
}
},

"when": {
"action": "unmarshall",
"operation": "AllTypes"
},
"then": {
"deserializedAs": {
}
}
},
{
"description": "Empty payload blob responses are unmarshalled",
"given": {
"response": {
"status_code": 204
}
},
"when": {
"action": "unmarshall",
"operation": "OperationWithExplicitPayloadBlob"
},
"then": {
"deserializedAs": {
}
}
}
// TODO header maps, service models supports this but Java SDK does not (not currently exercised)
// TODO header maps with prefix, services models do not support this, only used by S3
Expand Down