Migrating to System.Text.Json#176
Conversation
|
I cannot tell (yet) if we are are ready to merge it If you like to proceed this work:
|
# Conflicts: # paket.dependencies # paket.lock
| if isNull options then | ||
| let options = JsonSerializerOptions() | ||
| [ | ||
| JsonFSharpConverter( |
There was a problem hiding this comment.
Why here used not default converters config JsonFSharpConverter()?
There was a problem hiding this comment.
It only exists in .NET 5 as far as I know and it is not as powerful as FSharp.SystemtextJson
There was a problem hiding this comment.
I mean, why do you use
let options = JsonSerializerOptions()
[
JsonFSharpConverter(
JsonUnionEncoding.InternalTag
||| JsonUnionEncoding.NamedFields
||| JsonUnionEncoding.UnwrapSingleCaseUnions
||| JsonUnionEncoding.UnwrapRecordCases
||| JsonUnionEncoding.UnwrapOption) :> JsonConverter
]
|> List.iter options.Converters.Addas a default configuration, instead of
let options = JsonSerializerOptions()
[
JsonFSharpConverter() :> JsonConverter
]
|> List.iter options.Converters.Addfor some reason, author of FSharp.SystemTextJson choose different default configuration for JsonFSharpConverter
There was a problem hiding this comment.
We can go with the default configuration.
I don't know why he did that.
I see his defaults too verbose in JSON
| nuget Newtonsoft.Json | ||
| nuget System.Net.Http.Json | ||
| nuget System.Text.Json | ||
| nuget FSharp.SystemTextJson |
There was a problem hiding this comment.
Why do we need 3 explicitly referenced packages here?
nuget System.Net.Http.Json
nuget System.Text.Json
nuget FSharp.SystemTextJson
can we reference only FSharp.SystemTextJson?
There was a problem hiding this comment.
I thought that we will use JSON extensions to HttpClient and HttpResponseMessage
There was a problem hiding this comment.
I suppose we can
| invokeCode = (fun args -> <@@ () @@>), | ||
| BaseConstructorCall = fun args -> (baseCtor, args)) | ||
| ProvidedConstructor( | ||
| [ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = true)], |
There was a problem hiding this comment.
Do optional parameters not work?
There was a problem hiding this comment.
optionalValue is not the the bool argument - see here
SDK expect default value for provided parameter here, you code means true :> JsonSerializerOptions.
You may try to fix default parameters, but it may be tricky with null as default value.
There was a problem hiding this comment.
Ah, got it. I'll fix
There was a problem hiding this comment.
Try this
[
ProvidedConstructor(
[ProvidedParameter("httpClient", typeof<HttpClient>);
ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args ->
match args with
| [] -> failwith "Generated constructors should always pass the instance as the first argument!"
| _ -> <@@ () @@>),
BaseConstructorCall = fun args -> (baseCtor, args))
ProvidedConstructor(
[ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = (null:JsonSerializerOptions))],
invokeCode = (fun args -> <@@ () @@>),
BaseConstructorCall = fun args ->
let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @>
let args' = args @ [httpClient]
(baseCtor, args'))
] |> ty.AddMembers| let httpClient = <@@ RuntimeHelpers.getDefaultHttpClient defaultHost @@> | ||
| let args' = args @ [ httpClient; <@@ null @@> ] | ||
| let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @> | ||
| let args' = args @ [httpClient] |
There was a problem hiding this comment.
This arguments order is incorrect
There was a problem hiding this comment.
What is the correct one?
There was a problem hiding this comment.
The one that you revered in your commit [this; httpClient; options] as base class ctor expects
8459021#diff-4b6d8e966f147a1fd45efd232f8c3d4d993b57ddb43baa435c99211e4bb3e2ddL273-L276
There was a problem hiding this comment.
still no, you build [this; options; httpClient; null] instead of [this; httpClient; options]
There was a problem hiding this comment.
Like this?
let httpClient = <@ RuntimeHelpers.getDefaultHttpClient defaultHost @> :> Expr
let this :: tail = args
let args' = this :: httpClient :: tail
cce1ac0 to
06654ed
Compare
|
@xperiandri let me know about the result of your testing of NuGet package built from this branch |
|
Basically it is the version that is used to build and test the package. What version you propose to use? |
|
|
|
Also have a look at warnings from NuGe Package Explorer |

As long as I don't have .NET 4.6.1 targets installed I moved to .NET 4.8, but I suppose we can stay on .NET 4.6.1 (previously it was .NET 4.6.0)