Skip to content

Commit 379ce26

Browse files
committed
Adding more tests to show how a string marked with the jsonvalue trait and encoded as a base64 header should be decoded
1 parent 6db502a commit 379ce26

File tree

2 files changed

+48
-1
lines changed
  • core/protocols/aws-json-protocol/src/main/java/software/amazon/awssdk/protocols/json/internal/unmarshall
  • test/protocol-tests-core/src/main/resources/software/amazon/awssdk/protocol/suites/cases

2 files changed

+48
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ private HeaderUnmarshaller() {
4343

4444
/**
4545
* Unmarshalls a string header, taking into account whether it's a Base 64 encoded JSON value.
46+
* <p>
47+
* <em>Note:</em> This code does no attempt to validate whether the unmarshalled string does, in fact, represent valid
48+
* JSON values. The string value is returned as-is, and it's up to the user to validate the results.
4649
*
4750
* @param value Value to unmarshall
4851
* @param field {@link SdkField} containing metadata about member being unmarshalled.

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
}
3939
},
4040
{
41-
"description": "Base 64 string header with JSON trait is decoded",
41+
"description": "Base 64 string header with JSON trait is decoded, unquoted string preserved (invalid json)",
4242
"given": {
4343
"response": {
4444
"status_code": 200,
@@ -59,6 +59,50 @@
5959
}
6060
}
6161
},
62+
{
63+
"description": "Base 64 string header with JSON trait is decoded, quoted string preserved (valid json)",
64+
"given": {
65+
"response": {
66+
"status_code": 200,
67+
"headers": {
68+
"Encoded-Header": "InRvRGVjb2RlIg=="
69+
},
70+
"body": "{\"JsonValueMember\":\"dontDecode\"}"
71+
}
72+
},
73+
"when": {
74+
"action": "unmarshall",
75+
"operation": "JsonValuesOperation"
76+
},
77+
"then": {
78+
"deserializedAs": {
79+
"JsonValueHeaderMember": "\"toDecode\"",
80+
"JsonValueMember": "dontDecode"
81+
}
82+
}
83+
},
84+
{
85+
"description": "Base 64 string header with JSON trait is decoded, quoted json object preserved",
86+
"given": {
87+
"response": {
88+
"status_code": 200,
89+
"headers": {
90+
"Encoded-Header": "IntcImxpc3RcIjpbMSwyLDNdLFwibWFwXCI6e1wiZmlyc3RcIjpcInZhbHVlMVwiLFwic2Vjb25kXCI6XCJ2YWx1ZTJcIn19Ig=="
91+
},
92+
"body": "{\"JsonValueMember\":\"dontDecode\"}"
93+
}
94+
},
95+
"when": {
96+
"action": "unmarshall",
97+
"operation": "JsonValuesOperation"
98+
},
99+
"then": {
100+
"deserializedAs": {
101+
"JsonValueHeaderMember": "\"{\\\"list\\\":[1,2,3],\\\"map\\\":{\\\"first\\\":\\\"value1\\\",\\\"second\\\":\\\"value2\\\"}}\"",
102+
"JsonValueMember": "dontDecode"
103+
}
104+
}
105+
},
62106
{
63107
"description": "ISO 8601 Timestamp in header unmarshalled correctly",
64108
"given": {

0 commit comments

Comments
 (0)