Closed Evangelink closed 3 years ago
Correction issue is with a TimeSpan option
not a regular TimeSpan
.
Hi there @Evangelink I'll have a look, TimeSpan
should be supported without attributes indeed. I'll have a look 👍
The NonEmptyList
type, is that a DU, record or class? if it is a DU or record then it doesn't need anything special and it should be working.
Hey @Zaid-Ajaj, sorry I have been running late on posting my findings here.
The problem is actually for both the dotnetclient and the other client. It seems to be linked to structs and options.
I will post all the details tonight but here is globally the results:
TimeSpan
is goodTimeSpan option
failsStruct
attribute) fails@Evangelink no worries! It would be great if you could write the example types that aren't working properly 🙏
So these are failing, correct?
type OptionalTimeSpan = { value : TimeSpan option }
[<Struct>]
type StructDU =
| One of int
| Two of string
type RecordWithStructDU = { value : StructDU }
They do! To be exact for the the second part, I have only tested with single DUs so example would be
type OptionalTimeSpan = { value : TimeSpan option }
[<Struct>]
type StructDU = StructDU of string
type RecordWithStructDU = { value : StructDU }
Ahahah I am coming too late...
Anyways find the repro below:
#r "nuget: Fable.Remoting.DotnetClient"
open System
open Fable.Remoting.Json
open Newtonsoft.Json
type PersonId = PersonId of string
[<Struct>]
type StructPersonId = StructPersonId of string
type Record1 = { PersonId: PersonId }
type Record2 = { PersonId2: StructPersonId }
type Record3 = { PersonId3: PersonId option }
type Record4 = { PersonId4: StructPersonId option }
type Time1 = { Time: TimeSpan }
type Time2 = { Time2: TimeSpan option }
let record1 = { PersonId = PersonId "id" }
let record2 = { PersonId2 = StructPersonId "id" }
let record3 = { PersonId3 = Some (PersonId "id") }
let record4 = { PersonId4 = Some (StructPersonId "id") }
let time1 = { Time = TimeSpan.Zero }
let time2 = { Time2 = Some (TimeSpan.Zero) }
let converter = FableJsonConverter()
let roundTrip<'T> (obj: 'T) =
let result = JsonConvert.SerializeObject(obj, converter)
JsonConvert.DeserializeObject<'T>(result, converter)
|> printfn "%A"
// Ok
roundTrip<Record1>(record1)
roundTrip<Record2>(record2)
roundTrip<Record3>(record3)
roundTrip<Time1>(time1)
// Fail
roundTrip<Record4>(record4)
roundTrip<Time2>(time2)
Fixed as of Fable.Remoting.Json v2.19.0 🚀 please update your packages to latest and confirm if the problem has been resolved 🙏
Tested your repro code with dotnet fsi which uses v2.19.0, worked like a charm 😄
I was going to say I just tested it and it works but once again you beat me to it. Thanks!!!
Hi there,
I am using
Fable.Remoting
between my server (Saturn
based) and a WPF client (usingFable.Remoting.DotnetClient
) and I am facing some deserialization issues with some types:TimeSpan
, a home madeNonEmptyList
object (I could fix it by making the wrapped list record public) and maybe more when these will be "solved".See stacktrace (sorry for the few french words in the stack trace):
I am not sure if I am supposed to add some
JsonConverter
attributes on my types, if there is a missing configuration or what.My understanding was/is that I should simply use my F# types in client and server without any need for specific attributes or manual type wrapping but maybe I got things wrong.