Comments (3)
The Deserializer
isn't meant to be instantiated directly. You should use the DeserializerBuilder
so you can set all the options for it. It also adds all of the necessary objects and other required classes so it will work correctly.
I'm not an F# developer and don't know what the implications of removing option
from the definition will do with other code.
Using the DeserializerBuilder
and a couple of options and removing option
from the subThing
property made your code work:
[<CLIMutable>]
type SubThing = { value: string }
[<CLIMutable>]
type Thing = { subThing: SubThing }
open YamlDotNet.Serialization
let d = DeserializerBuilder().EnablePrivateConstructors().IncludeNonPublicProperties().Build()
"""
subThing:
value: "a"
"""
|> d.Deserialize<Thing>
|> printfn "%A"
Results:
{ subThing = { value = "a" } }
from yamldotnet.
YamlDotNet uses reflection by default to set and get values, there's some special handling for the nullable type because of the value field. We may be able to do the same thing for the FSharpOption
generic. I just don't have time to work on that right now.
If you search the codebase for Nullable
you can see where we do the checks for it. It would be a bit tricky with FSharp since that base generic class isn't included in the csharp and I don't want to include any dependencies, like fsharp. We currently don't impose non .net default libraries to use yamldotnet and I'd like to keep it that way.
To accomplish this we'd probably have to do type checking using string comparisons and more reflection to get/set the correct fields.
from yamldotnet.
I'm not an F# developer and don't know what the implications of removing option from the definition will do with other code.
It's basically equivalent to Nullable<T>
in C# land. So, removing it makes the field required.
I don't know enough about how YamlDotNet
works to know what's going on, but serializing the values of F# types also results in somewhat unexpected behavior which might hint at what's happening? It may be related to the implementation of Option
.
Using this script, for example, the second value doesn't successfully round-trip to and from YAML.
#r "nuget: YamlDotNet"
[<CLIMutable>]
type SubThing = { value: string }
[<CLIMutable>]
type Thing = { subThing: SubThing option }
open YamlDotNet.Serialization
let d = DeserializerBuilder().EnablePrivateConstructors().IncludeNonPublicProperties().Build()
let s = SerializerBuilder().Build()
{
subThing = None
}
|> s.Serialize
|> (fun v ->
printfn "serialize None:\n%A" v
v
)
|> d.Deserialize<Thing>
|> printfn "deserialize None:\n%A"
{
subThing = Some { value = "a" }
}
|> s.Serialize
|> (fun v ->
printfn "serialize Some:\n%A" v
v
)
|> d.Deserialize<Thing>
|> printfn "deserialize Some:\n%A"
serialize None:
"subThing@:
subThing:
"
deserialize None:
{ subThing = None }
serialize Some:
"subThing@: &o0
Value:
value@: a
value: a
subThing: *o0
"
(Line: 2, Col: 3, Idx: 17) - (Line: 2, Col: 8, Idx: 22): Property 'Value' not found on type 'Microsoft.FSharp.Core.FSharpOption`1[[FSI_0002+SubThing, FSI-ASSEMBLY2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]'.
Stopped due to error
from yamldotnet.
Related Issues (20)
- is it possible to style a string in a special way? HOT 3
- Set license expression on nuget package HOT 1
- Improve nuget package readme HOT 2
- Serialization / deserialization is not thread safe HOT 3
- Very large files fail to parse HOT 9
- Using ```YamlStream``` will cause "property not found" in ```IDeserializer.Deserialize()``` HOT 1
- Empty line in comments HOT 1
- Support for FSharp BCL List deserialization
- Aliases do not resolve correctly in Sequences HOT 1
- Better serialization of strings that look like integers (specifically, octals) HOT 2
- How to set custom Anchor names? HOT 6
- parse yaml file VB,net HOT 9
- Support keys longer than 1024 characters
- Deserialization into generic dictionary using WithAttemptingUnquotedStringTypeDeserialization deserializes hexadecimal value incorrectly.
- I am getting property not found error HOT 5
- How can I serialize to get a pretty json or flow yaml format string with newlines?
- SemanticErrorException on valid YAML HOT 1
- Deserialization exception when running quick start example on Linux HOT 1
- IncludeNonPublicProperties() broken in 16.0.0 HOT 3
- YamlIgnore is no longer respected during deserialization HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yamldotnet.