DynamoDB Type Serializer/Deserializer
NOTE: Handling DynamoDB Sets
DynamoDB has a distinct concept of sets (
Ss,Ns,Bs), whereas JSON does not. By default, the marshalling and unmarshalling in this library treats all JSON arrays as DynamoDB lists (AttributeValue::L). Consequently, even if you start with a DynamoDB string set (Ss), once it’s converted to JSON and then back again, it will become a list of strings (L).
NOTE: Large Numbers
DynamoDB’s
Ntype supports arbitrary-precision decimals, but JSON does not. Duringunmarshall, numbers are parsed asi64first, thenf64. Values outside both ranges (e.g. numbers with more than ~15 significant digits) fall back to a JSON string. On re-marshalling that string becomesAttributeValue::S, notAttributeValue::N. If you need to preserve large or high-precision numbers, store them as strings in DynamoDB.
NOTE: Binary Data (
B/Bs)
AttributeValue::Bhas no direct JSON equivalent. This library unmarshals binary blobs as a JSON array of byte values ([1, 2, 3, ...]). Re-marshalling that array producesAttributeValue::L(a list), notAttributeValue::B, so the roundtrip is lossy.Vec<u8>fields on Rust structs are serialized by serde_json as a number array and follow the same path; they are never stored asAttributeValue::B.
Simple Example for Value -> AttributeValue
use AttributeValue;
use ;
use dynamodb;
For struct that derive from Serialize, Deserialize
use HashMap;
use ;
use AttributeValue;
use dynamodb;