-
-
Notifications
You must be signed in to change notification settings - Fork 492
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
How do I serialize an F# record without having it output duplicate fields with @
signs at the end?
#1034
Comments
Here is another example. The results this library is giving me are bonkers.
Running the script with
|
The library does have tests that look sensible, so I am confused what the problem is. |
The library uses reflection to determine what to put in the yaml. Fsharp likes to make weird properties on its types, I think it was optional fields that caused us some grief. My guess is this is something that fsharp is now doing. To get around it you could make a custom type converter which will allow you to generate and read the yaml exactly how you want. |
@mrakgr can you try running the sample code in a console app. I only see the behavior you reported when running the code in FSX but not with a .NET console app. |
At works I am running a bunch of F# scripts for convenience, and it'd be inconvenient to convert them into a project. |
Month or two ago, I looked into this library, ran into the same issues and made my own Yaml serializer, I literally couldn't find a library for it out there. The reason why I decided to actually ask about this issue now is because I've noticed that you can serialize F# Maps (and mine can't), and you also have deserialization capabilities, which I needed. The way I got around the issues with serializing the records in my own serializer is by using the Fsharp reflection functions...
This'll give you exactly the record fields without the extras. The other case also shows how you can get all the items of a tuple in an array. Right now, the library isn't serializing them as a list. The F# script that I made is getting rewritten into Python by a coworker, so I am not going to pursue this issue further, and I am sorry that I won't have time to dive into the library to fix this. |
I think it's better to filter out those unspeaking properties in the library. |
Example code:
Here is what it outputs when I run it.
How do I prevent it from generating those extraneus duplicate fields ending in
@
?The text was updated successfully, but these errors were encountered: