-
Notifications
You must be signed in to change notification settings - Fork 59
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why here used not default converters config JsonFSharpConverter()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.Add
as a default configuration, instead of
let options = JsonSerializerOptions()
[
JsonFSharpConverter() :> JsonConverter
]
|> List.iter options.Converters.Add
for some reason, author of FSharp.SystemTextJson
choose different default configuration for JsonFSharpConverter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that we will use JSON extensions to HttpClient
and HttpResponseMessage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can
BaseConstructorCall = fun args -> (baseCtor, args)) | ||
ProvidedConstructor( | ||
[ProvidedParameter("options", typeof<JsonSerializerOptions>, optionalValue = true)], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do optional parameters not work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. I'll fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This arguments order is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the correct one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still no, you build [this; options; httpClient; null]
instead of [this; httpClient; options]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)