Skip to content

Commit c21ea24

Browse files
authored
Bug Fix to support Document Type for Explicit Payload members (aws#2736)
1 parent 6570864 commit c21ea24

File tree

6 files changed

+895
-7
lines changed

6 files changed

+895
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "",
4+
"type": "bugfix",
5+
"description": "Bug fix to handle DocumentType for Explicit payload members."
6+
}

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/marshall/JsonProtocolMarshaller.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.protocols.json.internal.marshall;
1717

1818
import static software.amazon.awssdk.core.internal.util.Mimetype.MIMETYPE_EVENT_STREAM;
19+
import static software.amazon.awssdk.core.protocol.MarshallingType.DOCUMENT;
1920
import static software.amazon.awssdk.http.Header.CHUNKED;
2021
import static software.amazon.awssdk.http.Header.CONTENT_LENGTH;
2122
import static software.amazon.awssdk.http.Header.CONTENT_TYPE;
@@ -177,6 +178,8 @@ void doMarshall(SdkPojo pojo) {
177178
Object val = field.getValueOrDefault(pojo);
178179
if (isBinary(field, val)) {
179180
request.contentStreamProvider(((SdkBytes) val)::asInputStream);
181+
} else if (isDocumentType(field) && val != null) {
182+
marshalDocumentType(field, val);
180183
} else {
181184
if (val != null && field.containsTrait(PayloadTrait.class)) {
182185
jsonGenerator.writeStartObject();
@@ -248,4 +251,19 @@ private SdkHttpFullRequest finishMarshalling() {
248251
return request.build();
249252
}
250253

254+
private boolean isDocumentType(SdkField<?> field) {
255+
return DOCUMENT.equals(field.marshallingType());
256+
}
257+
258+
private void marshalDocumentType(SdkField<?> field, Object val) {
259+
boolean isExplicitPayloadField = hasExplicitPayloadMember && field.containsTrait(PayloadTrait.class);
260+
if (isExplicitPayloadField) {
261+
jsonGenerator.writeStartObject();
262+
}
263+
MARSHALLER_REGISTRY.getMarshaller(field.location(), field.marshallingType(), val)
264+
.marshall(val, marshallerContext, field.locationName(), (SdkField<Object>) field);
265+
if (isExplicitPayloadField) {
266+
jsonGenerator.writeEndObject();
267+
}
268+
}
251269
}

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ private static SdkPojo unmarshallStructured(JsonUnmarshallerContext context, Jso
127127
private static Document unmarshallDocument(JsonUnmarshallerContext context,
128128
JsonNode jsonContent,
129129
SdkField<Document> field) {
130-
return jsonContent != null && !jsonContent.isNull() ? getDocumentFromJsonContent(jsonContent) : null;
130+
if (jsonContent == null) {
131+
return null;
132+
}
133+
return jsonContent.isNull() ? Document.fromNull() : getDocumentFromJsonContent(jsonContent);
131134
}
132135

133136
private static Document getDocumentFromJsonContent(JsonNode jsonContent) {
@@ -238,8 +241,11 @@ private static JsonNode getJsonNode(JsonNode jsonContent, SdkField<?> field) {
238241
if (jsonContent == null) {
239242
return null;
240243
}
241-
return isExplicitPayloadMember(field) ? jsonContent : jsonContent.field(field.locationName())
242-
.orElse(null);
244+
return isFieldExplicitlyTransferredAsJson(field) ? jsonContent : jsonContent.field(field.locationName()).orElse(null);
245+
}
246+
247+
private static boolean isFieldExplicitlyTransferredAsJson(SdkField<?> field) {
248+
return isExplicitPayloadMember(field) && !MarshallingType.DOCUMENT.equals(field.marshallingType());
243249
}
244250

245251
/**

0 commit comments

Comments
 (0)