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...
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...
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...
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...
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"
...
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...
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...
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<>...
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...
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...
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...
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...
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...
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 ...
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...
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...
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.