Skip to content

Commit ebee1aa

Browse files
committed
Fix for Marshalling List/Map of TimeStamps
1 parent cedb48a commit ebee1aa

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed
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": "Fix for NullPointerException while Marshalling List/Map of TimeStamps"
6+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void marshall(Boolean val, StructuredJsonGenerator jsonGenerator, JsonMar
105105
if (paramName != null) {
106106
jsonGenerator.writeFieldName(paramName);
107107
}
108-
TimestampFormatTrait trait = sdkField.getTrait(TimestampFormatTrait.class);
108+
TimestampFormatTrait trait = sdkField != null ? sdkField.getTrait(TimestampFormatTrait.class) : null;
109109
if (trait != null) {
110110
switch (trait.format()) {
111111
case UNIX_TIMESTAMP:

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

+40
Original file line numberDiff line numberDiff line change
@@ -474,5 +474,45 @@
474474
}
475475
}
476476
}
477+
},
478+
{
479+
"description": "TimeStampMap member in the payload is marshalled as seconds with millisecond precision",
480+
"given": {
481+
"input": {
482+
"MapOfTimeStamp": {
483+
"key1": 1422172801123
484+
}
485+
}
486+
},
487+
"when": {
488+
"action": "marshall",
489+
"operation": "AllTypes"
490+
},
491+
"then": {
492+
"serializedAs": {
493+
"body": {
494+
"jsonEquals":"{\"MapOfTimeStamp\": {\"key1\": 1422172801.123}}"
495+
}
496+
}
497+
}
498+
},
499+
{
500+
"description": "TimestampList member in the payload is marshalled as seconds with millisecond precision",
501+
"given": {
502+
"input": {
503+
"ListOfTimeStamp": [1422172801123]
504+
}
505+
},
506+
"when": {
507+
"action": "marshall",
508+
"operation": "AllTypes"
509+
},
510+
"then": {
511+
"serializedAs": {
512+
"body": {
513+
"jsonEquals": "{\"ListOfTimeStamp\": [1422172801.123]}"
514+
}
515+
}
516+
}
477517
}
478518
]

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

+38
Original file line numberDiff line numberDiff line change
@@ -525,5 +525,43 @@
525525
]
526526
}
527527
}
528+
},
529+
{
530+
"description": "ListOfTimeStamp with known values unmarshalled correctly",
531+
"given": {
532+
"response": {
533+
"status_code": 200,
534+
"body": "{\"ListOfTimeStamp\": [1398796238.123]}"
535+
}
536+
},
537+
"when": {
538+
"action": "unmarshall",
539+
"operation": "AllTypes"
540+
},
541+
"then": {
542+
"deserializedAs": {
543+
"ListOfTimeStamp": [1398796238123]
544+
}
545+
}
546+
},
547+
{
548+
"description": "MapOfTimeStamp with known values unmarshalled correctly",
549+
"given": {
550+
"response": {
551+
"status_code": 200,
552+
"body": "{\"MapOfTimeStamp\": { \"key1\": 1398796238.123}}"
553+
}
554+
},
555+
"when": {
556+
"action": "unmarshall",
557+
"operation": "AllTypes"
558+
},
559+
"then": {
560+
"deserializedAs": {
561+
"MapOfTimeStamp": {
562+
"key1": 1398796238123
563+
}
564+
}
565+
}
528566
}
529567
]

test/protocol-tests/src/main/resources/codegen-resources/awsjson/service-2.json

+13-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@
9191
"PolymorphicTypeWithoutSubTypes":{"shape":"SubTypeOne"},
9292
"EnumMember":{"shape":"EnumType"},
9393
"ListOfEnums":{"shape":"ListOfEnums"},
94-
"MapOfEnumToEnum":{"shape":"MapOfEnumToEnum"}
94+
"MapOfEnumToEnum":{"shape":"MapOfEnumToEnum"},
95+
"ListOfTimeStamp":{"shape":"ListOfTimeStamp"},
96+
"MapOfTimeStamp":{"shape":"MapOfTimeStamp"}
9597
}
9698
},
9799
"BaseType":{
@@ -294,6 +296,15 @@
294296
"SubTypeOneMember":{"shape":"String"}
295297
}
296298
},
297-
"Timestamp":{"type":"timestamp"}
299+
"Timestamp":{"type":"timestamp"},
300+
"ListOfTimeStamp":{
301+
"type":"list",
302+
"member":{"shape":"Timestamp"}
303+
},
304+
"MapOfTimeStamp":{
305+
"type":"map",
306+
"key":{"shape":"String"},
307+
"value":{"shape":"Timestamp"}
308+
}
298309
}
299310
}

test/protocol-tests/src/main/resources/codegen-resources/restjson/service-2.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@
239239
"PolymorphicTypeWithoutSubTypes":{"shape":"SubTypeOne"},
240240
"EnumMember":{"shape":"EnumType"},
241241
"ListOfEnums":{"shape":"ListOfEnums"},
242-
"MapOfEnumToEnum":{"shape":"MapOfEnumToEnum"}
242+
"MapOfEnumToEnum":{"shape":"MapOfEnumToEnum"},
243+
"ListOfTimeStamp":{"shape":"ListOfTimeStamp"},
244+
"MapOfTimeStamp":{"shape":"MapOfTimeStamp"}
243245
}
244246
},
245247
"BaseType":{
@@ -753,6 +755,15 @@
753755
}
754756
},
755757
"Timestamp":{"type":"timestamp"},
758+
"ListOfTimeStamp":{
759+
"type":"list",
760+
"member":{"shape":"Timestamp"}
761+
},
762+
"MapOfTimeStamp":{
763+
"type":"map",
764+
"key":{"shape":"String"},
765+
"value":{"shape":"Timestamp"}
766+
},
756767
"EventStreamOperationRequest": {
757768
"type": "structure",
758769
"required": [

0 commit comments

Comments
 (0)