-
-
Notifications
You must be signed in to change notification settings - Fork 491
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
Global toggle for quoting strings when serializing #791
Comments
This has been a feature I e seen requested a couple of times. It wouldn’t be hard to implement. I may have time to do it tonight after I work through at least one other pull request. We also do accept community pull requests if I can’t get to it. I would do it as another method on the serializer builder, passing an option to the required class that does the serialization. It’s where it specifies the type of scalar based on a reflex. |
I think this is the line that needs to be changed.
|
Great!
EDIT: @EdwardCooke I cannot get to get the unit test working. Is something special that I should be doing? I'm using EDIT2: I was missing cloning the submodules. Sorry hehe. But now a lot of the tests fail. Maybe I am missing something more. :/ EDIT3: Opened this #792 |
There’s a quoting style enum that would be best to pass in.
…________________________________
From: jhm-ciberman ***@***.***>
Sent: Wednesday, March 29, 2023 6:07:06 PM
To: aaubry/YamlDotNet ***@***.***>
Cc: Edward Cooke ***@***.***>; Comment ***@***.***>
Subject: Re: [aaubry/YamlDotNet] Global toggle for quoting strings when serializing (Issue #791)
Great!
Question: Does it makes sense to let users customize the quoting behaviour? As far as I know, double quotes let the user use escape characters (\n, \t) whereas single quotes don't.
1. Should the TypeAssigningEventEmmiter receive in it's constructor a bool doubleQuoteStrings and bool doubleQuoteEnums?
2. Or it's better to have something like QuotingMode stringQuotingMode and QuotingMode enumQuotingMode?
—
Reply to this email directly, view it on GitHub<#791 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ATMSFE4XRDOKNORCXNMYLZTW6TFCVANCNFSM6AAAAAAWMRMF4A>.
You are receiving this because you commented.Message ID: ***@***.***>
|
Passing in the scalar style as a default scalar style would be the route I would go. |
This PR is open and awaiting a comment to be resolved. It will allow specifying the default quote style |
That pr is approved. You can now set a default quoting policy. I’m closing this issue since it’s resolved now. |
Is your feature request related to a problem? Please describe.
I am making a mod loader system for a game and I would prefer every string (and maybe enums) to be quoted in double quotes to avoid any confusion for moders (and for myself) when authoring yaml files about special characters.
A typical manifest.yaml file for my game would look like this:
Currently YamlDotNet serializes every string without quotes.
Describe the solution you'd like
I would want a simple togle or simple way to force every string to be quoted. I'm not sure about what the ideal API would be.
Describe alternatives you've considered
I know I can force quoting via
[YamlMember]
attribute, but I would want a global toggle for every serialized string, because It's very cumbersome and easy to forget to add aYamlMemberAttribute
to every DTO object.I also spent a lot of time trying to use the solution in this comment but I cannot get it to only quote string values. It quotes everything including property names, which looks ugly to me.
Additional context
I'm very happy with YamlDotNet. And Writting custom YamlTypeConverters is very fun. Thanks for your amazing work! ❤️
The text was updated successfully, but these errors were encountered: