Skip to content

Commit d51b3e3

Browse files
committed
Fixing CBOR unmarshalling of blobs and running Kinesis integ test
1 parent 8beff09 commit d51b3e3

File tree

5 files changed

+32
-1
lines changed

5 files changed

+32
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"category": "AWS SDK for Java V2",
3+
"type": "bugfix",
4+
"description": "Fixes Issue [#864](https://github.com/aws/aws-sdk-java-v2/issues/864) by checking for embedded JSON objects while unmarshalling bytes."
5+
}

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/dom/SdkEmbeddedObject.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ private SdkEmbeddedObject(Object embeddedObject) {
3737
/**
3838
* @return The embedded object that was returned by the {@link JsonParser}.
3939
*/
40+
@Override
4041
public Object embeddedObject() {
4142
return embeddedObject;
4243
}

core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/dom/SdkJsonNode.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ default String asText() {
3737
return null;
3838
}
3939

40+
/**
41+
* @return The embedded object value of the node. See {@link SdkEmbeddedObject}.
42+
*/
43+
default Object embeddedObject() {
44+
return null;
45+
}
46+
4047
/**
4148
* @param fieldName Field to get value for.
4249
* @return Value of field in the JSON object if this node represents an object, otherwise returns null.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package software.amazon.awssdk.protocols.json.internal.unmarshall;
1717

18+
import static software.amazon.awssdk.protocols.core.StringToValueConverter.TO_SDK_BYTES;
19+
1820
import java.io.IOException;
1921
import java.time.Instant;
2022
import java.util.Collections;
@@ -77,7 +79,7 @@ private static JsonUnmarshallerRegistry createUnmarshallerRegistry() {
7779
.payloadUnmarshaller(MarshallingType.BIG_DECIMAL, new SimpleTypeJsonUnmarshaller<>(
7880
StringToValueConverter.TO_BIG_DECIMAL))
7981
.payloadUnmarshaller(MarshallingType.BOOLEAN, new SimpleTypeJsonUnmarshaller<>(StringToValueConverter.TO_BOOLEAN))
80-
.payloadUnmarshaller(MarshallingType.SDK_BYTES, new SimpleTypeJsonUnmarshaller<>(StringToValueConverter.TO_SDK_BYTES))
82+
.payloadUnmarshaller(MarshallingType.SDK_BYTES, JsonProtocolUnmarshaller::unmarshallSdkBytes)
8183
.payloadUnmarshaller(MarshallingType.INSTANT, new SimpleTypeJsonUnmarshaller<>(INSTANT_STRING_TO_VALUE))
8284
.payloadUnmarshaller(MarshallingType.SDK_POJO, JsonProtocolUnmarshaller::unmarshallStructured)
8385
.payloadUnmarshaller(MarshallingType.LIST, JsonProtocolUnmarshaller::unmarshallList)
@@ -92,6 +94,21 @@ private static Map<MarshallLocation, TimestampFormatTrait.Format> getDefaultTime
9294
return Collections.unmodifiableMap(formats);
9395
}
9496

97+
private static SdkBytes unmarshallSdkBytes(JsonUnmarshallerContext context,
98+
SdkJsonNode jsonContent,
99+
SdkField<SdkBytes> field) {
100+
if (jsonContent == null || jsonContent.isNull()) {
101+
return null;
102+
}
103+
// Binary protocols like CBOR may already have the raw bytes extracted.
104+
if (jsonContent.embeddedObject() != null) {
105+
return SdkBytes.fromByteArray((byte[]) jsonContent.embeddedObject());
106+
} else {
107+
// Otherwise decode the JSON string as Base64
108+
return TO_SDK_BYTES.convert(jsonContent.asText(), field);
109+
}
110+
}
111+
95112
private static SdkPojo unmarshallStructured(JsonUnmarshallerContext context, SdkJsonNode jsonContent, SdkField<SdkPojo> f) {
96113
if (jsonContent == null || jsonContent.isNull()) {
97114
return null;

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@
687687
<configuration>
688688
<includes>
689689
<include>**/*IntegrationTest.java</include>
690+
<include>**/*IntegrationTests.java</include>
690691
<include>**/*IntegTest.java</include>
691692
<include>**/RunCucumberTest.java</include>
692693
</includes>

0 commit comments

Comments
 (0)