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

Extracting MsgPack from String of bytes - rust

I am trying to write a wrapper function for read a string that contains Vec[u8] (that are really just MsgPacks) and convert them to native rust structs, my code looks like this use rmp_serde::{decode, from_slice}; use…
asosnovsky
  • 2,158
  • 3
  • 24
  • 41
0
votes
1 answer

Generic return types in traits for implementations that return non object-safe traits

I'm new to Rust and I wanted to learn the language and get a better understanding by implementing some small projects. My first attempt was to parse JSON data received from an MQTT Broker. I was very pleased how easy it was to accomplish this with…
BeneSim
  • 80
  • 5
0
votes
1 answer

I get a "no 'Json' in root" error when building a rust rocket api

So I was trying to follow the example from https://medium.com/sean3z/building-a-restful-crud-api-with-rust-1867308352d8 to build a simple REST API. Half way through, the rust compiler gives me the the following error: unresolved imports…
MWhatsUp
  • 41
  • 6
0
votes
1 answer

Deserializing different data structures with rust serde

I am trying to deserialize JSON that is received from Web API and has some unnecessarily deep structure. With serde, is it possible to deserialize JSON like: { "unnecessarily": { "deep": { "structure": { …
0
votes
1 answer

serder_json heserialize map with value being Number or boolean or String

I've been trying to deserialize a JSON containing an object which values can only be a String, a Boolean or a Number. Here is the code I use for that: use serde::{Deserialize, Serialize}; use serde_json::Number; use…
Jeremie
  • 378
  • 1
  • 3
  • 15
0
votes
1 answer

serde - Multiple defaults grouped together?

I'm trying to load a Toml file with Serde, it contains multiple booleans, I want to default them all to false if not found in the text file. My implementation currently is: #[derive(serde::Deserialize,…
Tomaz Canabrava
  • 2,320
  • 15
  • 20
0
votes
1 answer

How to make serde deserialize BigInt as u64?

I'm using toml and num-bigint with the serde feature to deserialize the following data: [[trades]] action = "Buy" date_time = 2019-04-15T15:36:00+01:00 fee = [1, [44000000]] id = "#1" price = [-1, [20154500000]] quantity = [1, [200000000]] But I'm…
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

How can I implement the Deserialize trait on the BigInt struct from the num library?

I'm using toml to parse data, and I have this struct: use serde_derive::Deserialize; use toml::value::Datetime; #[derive(Debug, Deserialize)] pub struct Trade { pub action: Action, pub date_time: Datetime, pub exchange: Exchange, …
Paul Razvan Berg
  • 16,949
  • 9
  • 76
  • 114
0
votes
1 answer

What is the best way to deserialize JSON and put the leaf data into Rc structs?

I have a JSON file with some repeating object structure and strings like below. { "array": [ { "data": [ "blih", "blah", "bloh" ] }, ... ] } My best understanding of Rust would be…
NebulaFox
  • 7,813
  • 9
  • 47
  • 65
0
votes
1 answer

Deserialize numbered items using serde

I am trying to deserialize JSON data that looks like the following using serde: { "item1": "Foo", "item2": "Bar", "item3": "Baz", "item4": null, "item5": null, "description1": "something", "description2": "another thing", …
carloabelli
  • 4,289
  • 3
  • 43
  • 70
0
votes
2 answers

Deserialize json based on an enum in the json

Is it possible to use a value in JSON to determine how to deserialize the rest of the JSON using serde? For example, consider the following code: use serde::{Serialize, Deserialize}; use serde_repr::*; #[derive(Serialize_repr, Deserialize_repr,…
fowlball1010
  • 343
  • 3
  • 13
0
votes
1 answer

Serde_json serialize to_string with a generic

I'm trying to serialize the params paramter of the send method. fn send(method: &str, params: T) -> () { println!("{:?}", serde_json::to_string(¶ms)); // Rest of actual code that works with 'method' and 'params' } fn main() { …
Nastezz
  • 3
  • 6
0
votes
1 answer

I am getting the trait bound `T: sns_pub::_IMPL_DESERIALIZE_FOR_Message::_serde::Serialize` is not satisfied

I am trying to serialize a stuct with a generic member I get the error 'equired because of the requirements on the impl of sns_pub::_IMPL_DESERIALIZE_FOR_Message::_serde::Serialize for sns_pub::Message #[derive(Debug, PartialEq, Serialize,…
ymoharaza
  • 11
  • 4
0
votes
0 answers

How to join to another table when serializing a Diesel type?

I'm trying to implement a serializer for my struct: #[derive(Queryable, Debug, Clone, Serialize, Deserialize)] struct One { two_id: i32, } #[derive(Queryable, Debug, Clone, Serialize, Deserialize)] struct Two { id: i32, } I'd like to get…
Koschi13
  • 549
  • 1
  • 4
  • 21
0
votes
0 answers

How to serialize/deserialize space-separated string into data struct?

For example, I have a string dog 5 true and want to serialize it into a Rust data struct using serde: struct Pet { pub name: String, pub age: u32, pub alive: bool, } Is it possible? If it is, how to accomplish that with Serde custom…
bhat
  • 13
  • 5