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

Force selected strings to marshal as string enclosed with double quotes #556

Closed
sachintaksande opened this issue Nov 27, 2019 · 2 comments
Closed

Comments

@sachintaksande
Copy link

Hello, I have a requirement where a mapping with key "key" and value as string like 12:34 should be marshalled as key: "12.34". I searched for all possible documentation but could not find it. Could you please suggest how to implement this requirement. What I tried while debugging is changing the value of "canUsePlain" in encode.go at runtime to false and it worked as expected. But there is no certain way to enforce this behavior for a selected property that I could find.

@niemeyer
Copy link
Contributor

Marshaling will not quote values unless they change their meaning when unquoted. At the moment if you want to force this, you can either use yaml.Node in v3 or define an Unmarshaler interface that returns a Node with the custom styling.

@danielfbm
Copy link

Marshaling will not quote values unless they change their meaning when unquoted. At the moment if you want to force this, you can either use yaml.Node in v3 or define an Unmarshaler interface that returns a Node with the custom styling.

Hi @niemeyer , could you kindly provide examples? It will be helpful for other that are trying to achieve the desired result with a quick glance.

Thanks for the tip on the custom Unmarshaler, it solved the problem for me

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

3 participants