serde Questions

2

I'm trying to deserialize MathML using Serde and Quick-XML in Rust. I'm having trouble trying to write the structs because of the recursive nature of MathML. Here's a minimal, reproducible example:...
Communard asked 11/6, 2021 at 7:3

1

Solved

I want to deserialize the following struct using serde_json. The parent_id field should accept an integer or a null, but I want it to return an error if the field is missing. #[derive(Debug, Serial...
Submultiple asked 9/7 at 9:51

4

Solved

I have a struct containing a byte array that I would like to serialize and deserialize to and from binary, but it only works for arrays up to 32 elements. Here is my minimal example code main.rs: #...
Stopping asked 14/2, 2018 at 7:45

2

Solved

I am using Rust to write a REST API and my Flutter client defines the entity like this: class WordDefinition { String type; String name; List<String> values; WordDefinition({ this.type,...
Catamite asked 7/11, 2021 at 10:19

2

I have some JSON text data with fields that can be either strings or arrays of strings. Here are four possible examples: { "keya": "some string", "keyb": &quot...
Posthaste asked 29/11, 2022 at 14:38

1

Solved

To familiarize myself with Rust, I took it upon myself to write a bloom filter that is backed by a BitVec. Part of that will include a save method that serializes the whole struct using serde and w...
Piegari asked 13/2 at 21:12

3

Solved

I have created a serialize_foo function that can serialize the Foo struct. struct Foo(i32) <- The Foo struct looks like this. The Foo struct is used in another struct Bar that looks like this: s...
Hennie asked 2/10, 2022 at 5:57

4

Solved

I want to deserialize the chemical elements JSON file from Bowserinator on github using Serde. For this I created a structure with all the needed fields and derived the needed macros: #[derive(Ser...
Katharinekatharsis asked 26/5, 2017 at 15:41

2

Solved

I have a question about memory allocation strategies in a specific situation. I have a large number of structs that are coming from a JSON API via serde. There is a specific field in the JSON respo...
Pump asked 28/12, 2023 at 23:55

5

Solved

I have a JSON API that returns an object that looks like this: { "PrivatePort": 2222, "PublicPort": 3333, "Type": "tcp" } To capture this, I have an enum and a struct: #[derive(Eq, PartialEq...
Anti asked 12/8, 2019 at 23:47

2

Solved

I have successfully used serde_json to deserialize and serialize JSON. My setup looks somewhat like this (very simplified): use serde::{Deserialize, Serialize}; use serde_json; use serde_with::skip...
Gravante asked 23/10, 2021 at 19:29

4

Solved

Given a yaml with a map of items, items: item1: uid: ab1234 foo: bar item2: uid: cd5678 foo: baz how can I parse it with serde into a Vec<Item> with a new field, "name", gene...
Icebreaker asked 27/11, 2023 at 5:52

5

Solved

I'm writing a crate that interfaces with a JSON web API. One endpoint usually returns responses of the form { "key": ["value1", "value2"] }, but sometimes there's only one value for the key, and th...
Translation asked 14/12, 2016 at 19:53

3

Solved

I ran into a problem trying to create a generic vector for a struct. This was my first attempt: #[derive(Serialize)] struct Card { sections: Vec<Section<dyn WidgetTrait>> } #[derive(S...
Evvy asked 25/4, 2018 at 12:5

4

Solved

I'd like to use Serde to parse some JSON as part of a HTTP PATCH request. Since PATCH requests don't pass the entire object, only the relevant data to update, I need the ability to tell between a v...
Circosta asked 2/6, 2017 at 14:12

2

Solved

I am completely new to Rust coming from JS/TS I have already seen other questions like: How do I iterate over elements of a struct in Rust? but they didn't get me to a real answer. I am trying to i...
Jerrine asked 30/3, 2022 at 11:31

1

I want to deserialize a pretty deep JSON to Rust struct: { "root": { "f1": { "f2": { "f3": 123 } } } } When deriving Deserialize, I will have to crea...
Yarbrough asked 28/8, 2020 at 9:23

3

Solved

I have a struct which implements Deserialize and uses the serde(deserialize_with) on a field: #[derive(Debug, Deserialize)] struct Record { name: String, #[serde(deserialize_with = "deserialize_...
Shuffleboard asked 11/7, 2019 at 8:44

1

I want to deserialize a string of JSON data into a struct with multiple fields and return an error if the ordering of the serialized data does not match the order of the fields in the struct. I hav...
Penchant asked 3/5, 2021 at 8:50

1

Solved

Serde derive macros come with the ability to control how a field is serialized/deserialized through the #[serde(with = "module")] field attribute. The "module" should have seria...
Muldoon asked 10/8, 2021 at 1:1

1

Solved

For context: I'm writing a ray tracer in Rust but I'm struggling with finding a good way to load the scene in a filesystem-agnostic way. I'm using serde so that I don't have to invent my own file f...
Veto asked 7/8, 2020 at 16:58

1

I'm decoding a reqwest::Response to JSON. Usually that works fine, but in some rare cases the remote server returns a response that doesn't fit my struct that I'm using for deserialization. In thos...
Button asked 30/1, 2022 at 22:0

2

Solved

Using serde_json, I have JSON objects with Strings that I need to convert to floats. I've stumbled upon a custom deserializer solution, but it seems like a hack. Here is a working playground exampl...
Lubra asked 29/6, 2017 at 23:12

3

In Serde serializers, how to add an additional field: #[derive(Serialize)] struct X { a: u32, b: u32, c: u32, } I want to add to JSON serialization field d with value "qwe". How witho...
Julianejuliann asked 23/2, 2023 at 19:36

4

Solved

When trying to serialize Option<chrono::DateTime<Utc>> I'm encountering an error: error[E0308]: mismatched types --> src/main.rs:39:14 | 39 | #[derive(Serialize, Debug)] | ^^^^^^^...
Flameproof asked 2/6, 2021 at 10:44

© 2022 - 2024 — McMap. All rights reserved.