So I'm using scylla's rust driver, and I'm working on a websocket which lets me send "commands" to it to insert / update / select data. Currently I've gotten pretty much everything to work besides being able to serialize a vec of hashmaps.
When I try I just get this error:
ArrayObject: SerializationError(BuiltinSerializationError { rust_name: "alloc::vec::Vec<std::collections::hash::map::HashMap<alloc::string::String, scyllatcp::structs::common::Value>>", got: List(UserDefinedType { type_name: "tokens_type", keyspace: "kstltest", field_types: [("token_", Text), ("created_date", Timestamp), ("ip", Text), ("flags", Int), ("token_id", Text)] }), kind: SetOrListError(ElementSerializationFailed(SerializationError(BuiltinTypeCheckError { rust_name: "std::collections::hash::map::HashMap<alloc::string::String, scyllatcp::structs::common::Value>", got: UserDefinedType { type_name: "tokens_type", keyspace: "kstltest", field_types: [("token_", Text), ("created_date", Timestamp), ("ip", Text), ("flags", Int), ("token_id", Text)] }, kind: MapError(NotMap) }))) })
I'm pretty new to rust so I'm unsure how to fix this.
So Currently I've tried:
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(untagged)]
pub enum Value {
Str(String),
Bool(bool),
Num(i32),
Null,
Array(Vec<Value>),
Map(Vec<(Value, Value)>),
Date(String),
ArrayObject(Vec<HashMap<String, Value>>),
}
impl SerializeCql for Value {
fn serialize<'b>(
&self,
typ: &scylla::frame::response::result::ColumnType,
writer: scylla::serialize::CellWriter<'b>,
) -> Result<
scylla::serialize::writers::WrittenCellProof<'b>,
scylla::serialize::SerializationError,
> {
match self {
&Value::Str(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
&Value::Num(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
// &Value::Int(ref value) => {
// scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
// }
&Value::Bool(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
&Value::Null => {
scylla::serialize::value::SerializeCql::serialize(&None::<String>, typ, writer)
}
&Value::Array(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
&Value::Map(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
&Value::Date(ref value) => {
scylla::serialize::value::SerializeCql::serialize(value, typ, writer)
}
&Value::ArrayObject(ref value) => {
match scylla::serialize::value::SerializeCql::serialize(value, typ, writer) {
Ok(value) => Ok(value),
Err(err) => {
println!("[Error] Failed to serialize ArrayObject: {:?}", err);
Err(err)
},
}
}
}
}
}
Which for the most part works besides at the ArrayObject, where I'm getting that issue.
I've also tried making the Vec<HashMap<String, Value>> its custom struct, then implementing SerializeCql on that struct, but got the same issue.