serde Questions

2

Solved

My goal is to (de)serialize objects with RFC-3339 timestamps from Json to Rust structs (and vice versa) using serde and time-rs. I would expect this ... use serde::Deserialize; use time::{OffsetDat...
Chortle asked 12/7, 2022 at 19:45

2

Solved

I'm serializing a HashMap with serde, like so: #[derive(Serialize, Deserialize)] struct MyStruct { map: HashMap<String, String> } HashMap's key order is unspecified, and since the hashing...
Fann asked 10/3, 2017 at 16:20

2

Solved

I use Serde to deserialize a custom configuration file written in YAML. The file can contain definitions of various kinds that I represent as internally tagged enums: OfKindFoo: kind: Foo bar: b...
Jennefer asked 14/4, 2020 at 20:34

1

Solved

I have the following two structs for which I derive serde traits. use serde::{Serialize, Deserialize}; #[derive(Serialize, Deserialize)] pub struct Item<'a> { pub id: &'a str, pub name...
Aback asked 21/11, 2022 at 10:7

0

I have been working on configuration parsing code and wondered if you could help me to pick the best types for this code. I am trying to parse the following TOML: [default] a=10 b="abc" ...
Willdon asked 20/11, 2022 at 14:31

2

Solved

I was wondering if it is possible to decode a JSON object in Rust that has an attribute name which is also a Rust keyword. I am working with the rustc-serialize crate and my struct definition looks...
Bergeman asked 17/3, 2015 at 17:18

2

Solved

Looking at the documentation of serde_json, I can't understand what trait I have to implement to make a struct serializiable to and deserializiable from json. The obvious answer could be Deserializ...
Bartholomeus asked 19/8, 2015 at 15:30

1

Solved

How can I use yaml tags with serde YAML, does it supports it? like: field1: &tag - item field2: *tag I've tried using references, but couldn't figure out the lifetimes and std::rc:Rc<>...
Hatpin asked 10/8, 2022 at 19:13

1

Solved

I am working on some code that takes a struct returned by an external library, serializes it to json, and serializes the json to protobuf using pbjson. The external library uses serde and implement...
Apatite asked 19/9, 2022 at 18:58

1

I'm trying to implement Serialize and Deserialize for an external enum and I have no idea how. It has From<u64> so all I want to do is just have that object serialize with that. #[derive(Seri...
Mixedup asked 17/4, 2021 at 20:28

1

I need to serialize a class of structs according to the TLV format with Serde. TLV can be nested in a tree format. The fields of these structs are serialized normally, much like bincode does, but...
Satiny asked 12/9, 2017 at 22:43

1

I need to use serde to serialize some XML data. The data has a pattern where a tag name in plural (e.g. CATS, DOGS) will contain multiple instances of subtags of the tag in singular (CAT, DOG), lik...
Ryder asked 26/10, 2019 at 14:54

3

Solved

I'm writing for a program that hooks into a web service which sends back JSON. When a certain property isn't there it provides a empty object, with all its fields as empty strings instead of exclu...
Petr asked 16/6, 2016 at 22:31

2

Solved

I have to deserialize JSON blobs where in some places the absence of an entire object is encoded as an object with the same structure but all of its fields set to default values (empty strings and ...
Err asked 2/10, 2018 at 15:10

1

Solved

I am querying an API for some data but their keys have hyphens instead of underscores in their names, and since I can't have hyphens in struct field names, I am unable to cast it. For example, my s...
Suburban asked 2/3, 2022 at 20:49

4

Solved

I want to serialize a HashMap with structs as keys: use serde::{Deserialize, Serialize}; // 1.0.68 use std::collections::HashMap; fn main() { #[derive(Serialize, Deserialize, Debug, PartialEq, Eq...
Cutis asked 11/7, 2018 at 3:40

3

Solved

I have a JSON structure that looks like this: { "type": "suite", "event": "started", "test_count": 1 } I want to deserialize into these structs: #[derive(Debug, Deserialize)] enum ResultType { ...
Digiacomo asked 4/12, 2019 at 0:37

1

I want to make a Serde struct that is capable of being deserialized from either borrowed data (serde_json::from_str) or owned data (serde_json::from_reader). I have read Understanding deserializer ...
Durango asked 1/8, 2020 at 4:0

1

Solved

Below is a non-functioning code example: use serde_json::json; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Model<T> where T: DeserializeOwned, { pub id: i32, pub info: Opti...
Shavonda asked 19/1, 2022 at 16:16

2

Iʼm trying to read a JSON stream, part of which looks like "data": [ "c1a8f800a4393e0cacd05a5bc60ae3e0", "bbac4013c1ca3482155b584d35dac185", "685f237d4fcbd191...
Hermaphrodite asked 7/1, 2022 at 0:6

1

Solved

Given the following JsonValue: let mut schema = json!({ "level": "strict", "rule": {} }); Where we would dynamically insert values to this JsonValue let value: json...
Hallerson asked 2/1, 2022 at 17:59

1

Solved

I'm trying to parse a JSON object into a HashMap in Rust using serde_json. With the following code, I get the error: error[E0507]: cannot move out of index of `Value` How do I get that Value into ...
Tolmann asked 14/12, 2021 at 0:55

2

Solved

I have a struct like this: #[derive(Serialize, Deserialize)] struct Thing { pub small_header: Header, pub big_body: Body, } I want to serialize this Thing to send over the network. I already h...
Swinge asked 10/10, 2018 at 5:15

1

I'd like to be able to read integers containing underscores (a thousands separator) - instrument: 5_000_000 other_field: this string contains an _ - instrument: 5_000_000 other_field: this string...
Hyaluronidase asked 10/12, 2021 at 11:35

1

Solved

In my current project I'm trying to store a chrono::Duration in a configuration struct, which will be serialized and deserialized occasionally using serde_json. Unfortunately, it appears that Seria...
Symposium asked 1/12, 2021 at 12:34

© 2022 - 2024 — McMap. All rights reserved.