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

Serialization of numeric valid strings #265

Closed
Narazaka opened this issue Jun 22, 2017 · 5 comments
Closed

Serialization of numeric valid strings #265

Narazaka opened this issue Jun 22, 2017 · 5 comments
Assignees

Comments

@Narazaka
Copy link

Narazaka commented Jun 22, 2017

Is there a way to serialize a string that is valid as a number, like "001122" and "1_2_3", as a string?

I tryed as below

var builder = new SerializerBuilder();
builder.EmitDefaults();
var serializer = builder.Build();
var dic = new Dictionary<string, object> {
  {"key", "001122"},
  {"key2", "1_2_3"},
};
Console.WriteLine(serializer.Serialize(dic));

and output was

key: 001122
key2: 1_2_3

then other yaml parser recognized as below (because of YAML specification)

js-yaml <<EOM
key: 001122
key2: 1_2_3
EOM
{
  "key": 594,
  "key2": 123
}

How can I serialize them as below?

key: "001122"
key2: "1_2_3"

I read YamlDotNet/Core/Emitter.cs but I have no good idea. (no source value type check?)

@aaubry
Copy link
Owner

aaubry commented Sep 28, 2017

I don't think that it is currently possible to change this behavior. But I agree that it should be fixed. I'll assign myself to it and see what can be done.

@aaubry aaubry self-assigned this Sep 28, 2017
@rohankhandelwal
Copy link

Are there any updates to this?

@Psilax
Copy link

Psilax commented Apr 1, 2021

I created my own implementation of a ChainedEventEmitter based on feedback from StackOverflow to handle strings that parse to int's and force quotes around them.
To bad this issue has been open for so long.

@joepb
Copy link

joepb commented Apr 20, 2021

3.5 years later and still no fix? :(

@EdwardCooke
Copy link
Collaborator

This issue was resolved in the 12.x releases.

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

6 participants