Skip to content

#[serde(try_from=...)] and #[serde(into=...)] not taken into account #402

@merlinaudio

Description

@merlinaudio

Hi!

I have a couple of types like Identifier which are serialized to/from a string, but internally store things different.

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "specta", derive(specta::Type))]
#[serde(try_from = "&str", into = "String")]
pub struct Identifier {
	parts: Vec<Alphanum>,
}

impl Display for Identifier {
	/* implementation */
}

impl FromStr for Identifier {
	/* implementation */
}

The generated binding for this is:

export type Identifier = { parts: Alphanum[] }

But it should be

export type Identifier = string;

I'd be perfectly content with a workaround, such as forcing a specific type:

#[specta(type = "String")]

But I'm not aware anything like that exists.

I'm using 2.0.0-rc.22

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions