Skip to content

Commit

Permalink
Deserialize string vec example
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinP122 committed Jun 14, 2024
1 parent 5b7e210 commit c5988d9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/api/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,18 @@ pub async fn retrieve_from_db<D: KvStoreConnection + Clone + Send + 'static>(
let db_result: Result<Option<Vec<Value>>, _> = db.lock().await.get_data(&address).await;

match db_result {
Ok(data) => r.into_ok("Data retrieved successfully", json_serialize_embed(data)),
Ok(data) => {

let elems = data
.into_iter()
.map(serde_json::from_str)
.collect::<Result<Vec<Value>>>()
.unwrap();

let json_val = Value::Array(elems);

return r.into_ok("Data retrieved successfully", json_serialize_embed(data))
},
Err(_) => r.into_err_internal(ApiErrorType::Generic(
"Full Valence chain retrieval failed".to_string(),
)),
Expand Down

0 comments on commit c5988d9

Please sign in to comment.