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 float of value 0 is omited #530

Closed
snowgoon88 opened this issue Sep 11, 2020 · 1 comment
Closed

Serialization of float of value 0 is omited #530

snowgoon88 opened this issue Sep 11, 2020 · 1 comment

Comments

@snowgoon88
Copy link

Hello,

float with zero (0f) value are not serialized. Is it on purpose ?

I have this Animat structure

public class Animat {
        public float animatRotDeg { get; set; }        
        public float animatMaxVelocity { get; set; }
}

when I serialize with

Animat anim = new Animat {
animatRotDeg = 0f,
animatMaxVelocity = 200f
}

var serializer = new SerializerBuilder().Build();
var yaml = serializer.Serialize( anim );

I have

animatMaxVelocity: 200

but if I use

Animat anim = new Animat {
animatRotDeg = 10f,
animatMaxVelocity = 200f
}

I have

animatRotDeg: 10
animatMaxVelocity: 200
@EdwardCooke
Copy link
Collaborator

I don't know what version it changed in, but the default appears to be defaulting to emit default values. If you want to change that, on the builder, you can call ConfigureDefaultValuesHandling and pass the appropriate enum value.

var serializer = new SerializerBuilder()
    .ConfigureDefaultValuesHandling(DefaultValuesHandling.Preserve)
    .Build();

I'm going to close this issue, if you need further help, let me know.

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