Closed
Description
Describe the bug
util-dynamodb convertToAttr throws error when trying to serialize ES6 classes
Refs: #1531 (comment)
SDK version number
master
Is the issue in the browser/Node.js/ReactNative?
N/A
To Reproduce (observed behavior)
A unit test is added under unsupported type in PR #1531
Expected behavior
Questionable, as v2 DynamodDB serializes ES6 class objects as maps.
Storing as string using JSON.stringify
is more helpful, as class properties can be deserialized using JSON.parse
:
- Example StackOverflow discussion: https://stackoverflow.com/a/40201783
- MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify
JSON.stringify will also store Date (ref: #1534) in ISO 8601 format as follows:
> const now = new Date();
> const serialized = JSON.stringify(now);
> const past = new Date(JSON.parse(serialized));
> now.getTime() === past.getTime()
true