Comments (2)
.WithAllowOverride()
should do what you need here.
from fsharp.systemtextjson.
Hi there, I've used other solutions before, and now that I've had time to continue testing the solution you mentioned WithAllowOverride
, I've found that it doesn't work as expected either!
#r "nuget: FSharp.SystemTextJson, 1.3.13"
open System.Text.Json.Serialization
open System.Text.Json
[<JsonFSharpConverter(UnionEncoding=(JsonUnionEncoding.Untagged))>]
type Untagged1 = A of int | B of string
let optInternalTag =
JsonFSharpOptions()
.WithUnionInternalTag() // <-
.WithUnionAllowUnorderedTag()
.WithUnionUnwrapFieldlessTags()
.WithUnwrapOption()
.WithAllowOverride() // add
.ToJsonSerializerOptions()
let valB = B "bbb"
let jsonB = JsonSerializer.Serialize(valB, optInternalTag)
jsonB |> printfn "%A" // expect: jsonB = "bbb"; actual: jsonB = "{"Item":"bbb"}"
let valueB = JsonSerializer.Deserialize<Untagged1>("bbb", optInternalTag)
// ^ System.Text.Json.JsonException: 'b' is an invalid start of a value.
// Path: $ | LineNumber: 0 | BytePositionInLine: 0.
This is a very nice library, thanks for the code!
from fsharp.systemtextjson.
Related Issues (20)
- Disallow null if not option-wrapped everywhere, not just for record fields HOT 6
- Allow using single-case unions as dictionary keys HOT 1
- Allow handling arbitrary Map keys as JSON object properties HOT 1
- [StructuralComparison] for `Skippable` HOT 3
- Record deserialization throws NRE if ignore null values is on
- Support Tuples HOT 1
- WithUnwrapOption(false) still serializes None as null HOT 5
- Regression in 1.2: NullReferenceException when serializing null record field HOT 3
- WithSkippableOptionFields fails roundtrip when option inside union
- Deserialize null or missing fields as None? HOT 6
- NotSupported exception when dictionary key is union (DU)
- Incorrect missing field name - seems to pick name of first null field, even if field is optional
- Allow overriding generic types
- Allow overriding property and union case attributes in options
- Can't parse Option<'T> from a json field that's either missing or null HOT 3
- Custom serializer/`JsonConverter` for a record HOT 1
- Allowing null fields example from the docs is not working HOT 2
- Do not use FSharp.SystemTextJson on types that do not have the [<JsonFSharpConverter>] attribute HOT 1
- How to upgrade from 0.17.4 for single case unions and skippable fields? HOT 4
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 fsharp.systemtextjson.