Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#[near] on structs does not forward #[serde] attributes #1182

Closed
encody opened this issue May 8, 2024 · 1 comment
Closed

#[near] on structs does not forward #[serde] attributes #1182

encody opened this issue May 8, 2024 · 1 comment
Labels

Comments

@encody
Copy link
Contributor

encody commented May 8, 2024

The new #[near] macro introduced in #1142 does not forward #[serde] attributes in struct definitions, but it appears that it does forward #[borsh] attributes:

#[derive(near_sdk::borsh::BorshSerialize)]
#[borsh(crate = "near_sdk::borsh")]
pub struct B1 {
    #[borsh(skip)] // OK
    field: u32,
}

#[near]
pub struct B2 {
    #[borsh(skip)] // OK
    field: u32,
}

#[derive(near_sdk::serde::Serialize)]
#[serde(crate = "near_sdk::serde")]
pub struct S1 {
    #[serde(skip)] // OK
    field: u32,
}

#[near]
pub struct S2 {
    #[serde(skip)] // ERROR: cannot find attribute `serde` in this scope
    field: u32,
}
@encody encody added the bug label May 8, 2024
@frol
Copy link
Collaborator

frol commented Jun 4, 2024

@encody #[near] only enables borsh serialization by default. #[serde(skip)] should work as soon as you enable json serialization: #[near(serializers = [borsh, json])]

@frol frol closed this as completed Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants