Questions tagged [serde]

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Serde is a framework for serializing and deserializing Rust data structures efficiently and generically.

Site

Repository

crates.io

839 questions
0
votes
1 answer

The trait Serialize is not implemented despite being implemented?

I'm using actix-web for creating an app for reclaiming packets, then inserting them into MongoDB database. I have a struct #[derive(Serialize, Deserialize, Debug)] pub struct Gyro{ /// GYRO FRONT + MIDDLE pub x0x800: [i32; 12], …
Patrox27
  • 3
  • 2
0
votes
1 answer

How do I serialize an enum to a number and deserialize from a number via serde-json?

struct ResponseData { success : bool, res_data : T, } struct FooRes { result:RESULT, } num RESULT { RESULT_OK = 0, RESULT_NG = 1, } fn test(){ let s = ResponseData::{ success : true, res_data : FooRes{ …
Ryo-chan
  • 31
  • 2
0
votes
1 answer

How do I serialize from request's Response with JSON into a typed struct?

I don't understand how I can convert a requests::Response to a serde JSON object. I tried this: extern crate requests; extern crate serde; #[macro_use] extern crate serde_derive; extern crate serde_json; fn get_json() -> requests::Response { …
XaniXxable
  • 109
  • 1
  • 9
0
votes
1 answer

How to just use custom serialisation for "stringy" serialisation?

I've recently got to grips with custom serialisation/deserialisation: https://stackoverflow.com/a/63846824/129805 I want to use this custom "stringy" serialisation (and des.) only for JSON and RON, while using the #[derive(Serialisation, ... for all…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
0
votes
0 answers

Cannot get the lifetimes right when implementing serde's sequence serializer for MessagePack

I want to write a no-std compatible MessagePack serializer/deserializer in Rust. I have most of the serialization working, but I am struggling with serializing structs, sequences and maps using serde. I copied a lot from serde_json_core, but I can't…
Karsten
  • 1,814
  • 2
  • 17
  • 32
0
votes
0 answers

How to split enum variants and their contents in Rust to generate correct JSON schema

With schemars, it is possible to generate a JSON schema from Rust code. Consider this JSON example: { "cause" : { "type" : "EVT1", "payload" : { "cause_id" : "ABC-123" } } } and the Rust code used to generate the…
nomad
  • 131
  • 1
  • 8
0
votes
1 answer

"key must be a string" when deserializing a JSON string with Serde

I'm building a React app utilizing Rust for complex computations. In this case I'm passing a JSON formatted string from the React app to Rust: { {'clientid': 1, 'category': 'Category #1', 'subcategory': 'Subcategory #1', 'cost': 1000.00}, …
chasahodge
  • 373
  • 1
  • 4
  • 11
0
votes
1 answer

How to modify a string inside a serde_json::Value::String?

I have a serde_json::Value containing a string that I want to modify, if possible without cloning the string. I would imagine you would do it like this: let mut value = Value::String("Hello world".to_string()); let mut string =…
Anders
  • 8,307
  • 9
  • 56
  • 88
0
votes
2 answers

Deserializing multiple JSON fields to a single Vec in serde

Could you please help me with the following problem? I have a JSON: { "some_other_field": "value", "option1": "value1", "option2": "value2", [...] "option10": "value10", } There are up to X optionX fields which are all…
0
votes
0 answers

How can I deserialize a single field from an array of objects with serde_json?

I have JSON where a key has an array of objects and I'm only interested in one of the strings within that: { "actors": [{ "name": "Bob", "foo": "bar" }, { "name": "Jim", "foo": "baz" }], "fruits": [{ …
SuperWig
  • 155
  • 3
  • 14
0
votes
0 answers

odbc_iter error: the trait `serde::ser::Serialize` is not implemented for `odbc_iter::value::Value`

Please help, I got this serde not implemented for trait error when i am trying out odbc_iter example let row = db.query::("SELECT 'hello world', CAST(42 AS INTEGER), CAST(10000000 AS BIGINT)") .expect("failed to run…
yih lim
  • 13
  • 3
0
votes
1 answer

Websocket JSON parsing type mismatch

I'm trying to hack together a simple WebSocket client using tungstenite that parses JSON. Most of the code comes from this example. If I do println!("{}", msg) It works fine, so I'm not sure why the type is mismatched (msg is supposedly a string…
SoGoddamnUgly
  • 706
  • 4
  • 9
0
votes
2 answers

How to use serde to deserialize a json formatted array of structs within a struct?

Suppose I have the following structs "Wheel" and "Car" where a "Car" can contain a list of Cars (a recursive definition). use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Wheel { #[serde(default,…
Nona
  • 5,302
  • 7
  • 41
  • 79
0
votes
1 answer

Serde Deserializer, how to have distinct behavior while decoding an `u8` directly and a `u8` in a `Vec`

I'm writing a Deserializer for a format that already exists, but the format has one peculiarity which I don't know how to implement in serde: // pseudo code fn example(){ // when decoding an u8 directly, the value 0x00 is invalid …
Augusto Hack
  • 2,032
  • 18
  • 35
0
votes
1 answer

Yew callback for different Json structs

I am using yew with the WebsocketService and sending jsonrpcs to a backend and receive the according answers. I have a problem to distinguish between valid and error jsonrpc answers. Within the model implementation, I create the callback via: let…
mostsignificant
  • 312
  • 1
  • 8