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

Configure enum deserialization? #39

Closed
frnsys opened this issue May 30, 2023 · 3 comments
Closed

Configure enum deserialization? #39

frnsys opened this issue May 30, 2023 · 3 comments

Comments

@frnsys
Copy link

frnsys commented May 30, 2023

Hi, thanks for this library, it's great.

Is it possible to configure enum deserialization? My input yaml has enum values serialized like Foo, Bar, but it looks like this library requires them to be serialized as camel case (foo, bar). Is it possible to have an attribute or something that specifies what casing scheme it should be deserialized with (similar to serde's rename_all)?

Thanks

@hadashiA
Copy link
Owner

hadashiA commented Jun 2, 2023

That's a fair point.

Unfortunately, currently it can only be set per enum member.

I have come up with a plan to implement the following features

Provide multiple EnumFormatters.
For example,

  • LowerCamelCaseEnumFormatter.
  • UpperCamelCaseEnumFormatter
  • maybe, etc.

The behavior can be changed globally by specifying them in YamlSerializerOptions.

In addition, a feature to specify a formatter for each type, as shown below, would satisfy the request.

[YamlFormatter(typeof(UpperCamelCaseEnumFormatter))]
enum Foo 
{
    A, 
    B, 
    C
}

@frnsys
Copy link
Author

frnsys commented Jun 5, 2023

That sounds great to me. For now I have a workaround that seems ok. Thanks again.

@hadashiA
Copy link
Owner

hadashiA commented Nov 6, 2023

In #60, serialization format of enum can now be specified.

[YamlObject(NamingConvention.UpperCamelCase)]
enum Foo 
{
    A, 
    B, 
    C
}

Not that it can only be changed for each enum type.

@hadashiA hadashiA closed this as completed Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants