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

Null value after deserializing an empty class with tag mapping #514

Open
tharel1 opened this issue Jul 21, 2020 · 2 comments
Open

Null value after deserializing an empty class with tag mapping #514

tharel1 opened this issue Jul 21, 2020 · 2 comments
Labels

Comments

@tharel1
Copy link

tharel1 commented Jul 21, 2020

Hello,

First of all, a big thanks for this amazing library which is indispensable in my project.

I try to deserialize the following yaml file :

- !damage
  value: 3
- !hello

I succesfully deserialize the "damage" class but the "hello" class is always null after the deserialization.
Also, when i add a new field to my hello class and to my yaml file, the hello class deserializes successfully...

The damage and the hello class :

class Damage : IAction
{
   public int Value { get; set; }
   public Damage() { }
}
class Hello : IAction
{
   public Hello() { }
}

And my yaml deserializer :

new DeserializerBuilder().WithNamingConvention(UnderscoredNamingConvention.Instance)
            .WithTagMapping("!damage", typeof(Damage))
            .WithTagMapping("!hello", typeof(Hello))
            .Build();

Maybe my yaml is incorrect and I can't have a tag without fields. But I still think I need it for my use case because I feel that it is a "cleaner" solution.

@pensono
Copy link
Contributor

pensono commented Jul 25, 2020

In yaml, and empty value indicates null. You'll need to use a block mapping here to indicate that you want an empty object and not a null one.

- !damage
  value: 3
- !hello {}

@EdwardCooke
Copy link
Collaborator

@pensono is correct on the null statement. Did his solution using the braces fix your problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants