libmir / asdf

JSON library
http://asdf.libmir.org
Boost Software License 1.0
20 stars 8 forks source link

[feature request] serde(rename_all) for enums #25

Open AndrejMitrovic opened 1 year ago

AndrejMitrovic commented 1 year ago

In Rust the serde macro can rename all enum members, for example:

#[serde(rename_all = "UPPERCASE")]
pub enum LoginType {
    Web = 0,
    Mobile = 1,
}

The D workaround for this is to use serdeKeys:

enum LoginType {
    @serdeKeys("WEB") Web,
    @serdeKeys("MOBILE") Mobile,
}

But would it be possible to add something similar in D that affects all the enum members? E.g.:

@serdeRenamed(Uppercase)
enum LoginType {
    Web,
    Mobile,
}

The exact syntax isn't that important to me.

9il commented 1 year ago

It can be implemented like http://mir-algorithm.libmir.org/mir_serde.html#.serdeIgnoreCase

I am no longer work on new features, but it could be added as part of mir migration to Phobos: https://forum.dlang.org/post/szljgyqtwfangdygcifs@forum.dlang.org