mockersf / serde_dynamodb

Talk with dynamodb using your existing structs thanks to serde

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support Maps

jatsrt opened this issue · comments

In certain cases if the object is "deep" enough, it will try to deserialize it as a "map". If you use the same implementation as struct, it should work:

fn deserialize_map<V>(self, visitor: V) -> Result<V::Value>
where V: serde::de::Visitor<'de> {
    match self.current_field {
        Index::None => visitor.visit_map(MapAccess::new(self, self.read.get_keys())),
        _ => {
            let map = self.read.get_attribute_value(&self.current_field).ok_or_else(|| Error {
                message: format!("missing struct for field {:?}", &self.current_field),
            })?;
            let hm = map.clone().m.ok_or_else(|| Error { message: "Missing".to_owned() })?;
            let keys = hm.keys().cloned().collect();
            let mut des = Deserializer::new(HashMapRead::new(hm));
            visitor.visit_map(MapAccess::new(&mut des, keys))
        }
    }
}

Giving this a bump as it would be really nice to have map support.

maps are supported for serialisation and deserialisation in v0.4.0