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

Add quotes for strings on model serialization #869

Closed
sunnamed434 opened this issue Nov 17, 2023 · 3 comments
Closed

Add quotes for strings on model serialization #869

sunnamed434 opened this issue Nov 17, 2023 · 3 comments

Comments

@sunnamed434
Copy link

sunnamed434 commented Nov 17, 2023

I want to add quotes for strings when serializing a model (class), but adding attributes on properties is not my case - because I want it automated.

I checked issues on this GitHub repo and stackoverflow to find answers to my question, but without success, I saw solutions but they either did not work or just added the quotes for everything.

I think about smth like this, I guess there should be a way to do that via event emitter or in another way.

var yamlSerializer = new SerializerBuilder()
                        .WithQuotesForStrings()
                        .Build();
Before:

- Id: Item1
  Value: Hello world 1!
- Id: Item2
  Value: Hello world 2!
- Id: Item3
  Value: 10
- Id: Item4
  Value: true

After:

- Id: "Item1"
  Value: "Hello world 1!"
- Id: "Item2"
  Value: "Hello world 2!"
- Id: "Item3"
  Value: 10
- Id: "Item4"
  Value: true
@EdwardCooke
Copy link
Collaborator

I’m pretty sure there’s a withdefaultquountingstyle method on the serializerbuilder that was added recently.

@sunnamed434
Copy link
Author

Thanks, solved!

var yamlSerializer = new SerializerBuilder()
                        .WithNamingConvention(CamelCaseNamingConvention.Instance)
                        .WithDefaultScalarStyle(ScalarStyle.DoubleQuoted) // add this line
                        .Build();

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