Skip to content
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

[Question] DotnetClient - serialization of private record type #269

Open
Evangelink opened this issue Aug 20, 2021 · 4 comments
Open

[Question] DotnetClient - serialization of private record type #269

Evangelink opened this issue Aug 20, 2021 · 4 comments

Comments

@Evangelink
Copy link

Hi,

I am wondering if it's possible to pass some extra information to the dotnet client serializer on how to deserialize some type?

I have defined a NonEmptyList type which is a simple wrapper around a List with the record as private.

#r "nuget: Fable.Remoting.DotnetClient"

open System

open Fable.Remoting.Json
open Newtonsoft.Json

let converter = FableJsonConverter()

let roundTrip<'T> (obj: 'T) =
    let result = JsonConvert.SerializeObject(obj, converter)
    JsonConvert.DeserializeObject<'T>(result, converter)
    |> printfn "%A"

type NonEmptyList<'T> =
    private {​ ​​List:'T list }​​​

type TestRecord = { ​​​TestList: NonEmptyList<string> }​​​
let testRecord = { ​​​TestList = { ​​​List = [ "" ] } ​​​}​​​

// Run the following and you have an error about private ctor (error makes sense). Remove the `private` keyword before the record and everything works fine.
roundTrip<TestRecord>(testRecord)

I would like to be able to deserialize this type but it seems that there is no way for me to pass a JsonConverter object. What would you recommend?

@Zaid-Ajaj
Copy link
Owner

Hi @Evangelink, I think the only right now for the FableJsonConverter is to accept types with public constructors. I need to double check

@jannesiera
Copy link

Is there a way to add support for this? We use this pattern a lot so that means we currently either can't use Fable.Remoting or we have to make a bunch of constructors public while they really shouldn't be (and has the potential to introduce bugs when someone forgets that the default constructor is off limits).

@Zaid-Ajaj
Copy link
Owner

Hi @jannesiera it has been a while since last time I looked into this issue and to be honest I don't know the status of it right now, if you could have a go at it, that would be great! I believe it was possible before so now not sure why it didn't work any more. I'll be happy to review PRs, then make time merge and publish the fixes

@jannesiera
Copy link

Unfortunately, I have very little time at the moment and won't be able to allocate the resources for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants