Skip to content

u128 is not supported with #[serde(flatten)] #625

@nlordell

Description

@nlordell

It looks like u128 is not supported with #[serde(flatten)] when deserializing JSON. The following snippet shows the problem.

use serde::Deserialize;

#[derive(Debug, Deserialize)]
struct Foo {
    a: u128,
}

#[derive(Debug, Deserialize)]
struct Bar {
    foo: Foo,
}

#[derive(Debug, Deserialize)]
struct Baz {
    #[serde(flatten)]
    foo: Foo,
}

fn main() {
    println!("{:?}", serde_json::from_str::<Foo>(r#"{"a":340282366920938463463374607431768211455}"#));
    println!("{:?}", serde_json::from_str::<Bar>(r#"{"foo":{"a":340282366920938463463374607431768211455}}"#));
    println!("{:?}", serde_json::from_str::<Baz>(r#"{"a":340282366920938463463374607431768211455}"#));
}

Outputs:

Ok(Foo { a: 340282366920938463463374607431768211455 })
Ok(Bar { foo: Foo { a: 340282366920938463463374607431768211455 } })
Err(Error("u128 is not supported", line: 1, column: 45))

This might be a serde_derive issue though, and not related to serde_json.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions