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

Serializing c# anonymous object #775

Open
igor-dragutinovic opened this issue Feb 7, 2023 · 3 comments
Open

Serializing c# anonymous object #775

igor-dragutinovic opened this issue Feb 7, 2023 · 3 comments
Labels

Comments

@igor-dragutinovic
Copy link

Describe the bug
I have a YAML schema that has an array of items that can have the same key, e.g.
choices:

  • correct: answer1
  • wrong: answer2
  • wrong: answer3
  • correct: answer4

In order to make this I used the following setup:
public List<object> choices { get; set; }
and the following usage of this property:
choices.Add( isCorrect ? new { correct = answer } : new { wrong = answer });

When serializing the object with this collection of anonymous objects, I have errors in the output (in bold):

choices:

  • correct: 30
  • wrong: 20
  • wrong: 40
  • &o0
    wrong: 10

or:

choices:

  • &o3
    wrong: false
  • correct: Java
  • wrong: true
  • wrong: Scala

Describe the solution you'd like
I would like to have a setup that enables proper serialization of anonymous objects.

Describe alternatives you've considered
Building the YAML object in the c# code instead of serialization.

@EdwardCooke
Copy link
Collaborator

Can you paste in a full code example that will reproduce this issue? I suspect it’s adding an anchor, just need to verify that I’d what is happening.

@EdwardCooke
Copy link
Collaborator

You can also try adding this on your serializer builder DisableAliases()

@EdwardCooke
Copy link
Collaborator

Did disablealiases work?

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

2 participants