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

Transferring private types #348

Open
DejanMilicic opened this issue Aug 15, 2023 · 3 comments
Open

Transferring private types #348

DejanMilicic opened this issue Aug 15, 2023 · 3 comments

Comments

@DejanMilicic
Copy link

I have a type that looks like this:

    module DateRange = 
        type T = private
            { 
                StartDate: DateTime option
                EndDate: DateTime option
            }

When making Fable.Remoting calls, NewtonSoft.Json complains that there is not public constructor exposed.
Removing private is a quick fix.

However, is there any other way I could resolve this without exposing properties of the type? E.g. would switching to some other serialization method work? What would be your recommendation in this case?

@Zaid-Ajaj
Copy link
Owner

Hi there @DejanMilicic I haven't tested what the binary serialization does to private fields, maybe you could try that and see if it fixes the problem? Otherwise I don't think there is a way to do this right now with Newtonsoft.Json 🤔

@Larocceau
Copy link

Hi! came here with the same problem as @DejanMilicic. Just wanted to confirm that turning on binary serialization does indeed fix the issue. Thanks @Zaid-Ajaj

@randrag
Copy link

randrag commented Aug 19, 2024

Hi @DejanMilicic, a quick note to say that private discriminated unions are successfully transferred.

I.e.,

module DateRange =
   type T = private T of {
      StartDate : Option<DateTime>
      EndDate : Option<DateTime>
}

I'm not sure whether this is by design, or by accident.

One upshot is that constrained types coming from the JS front end don't get constructed with the proper constructor, which leaves you vulnerable to exploits, since the JSON can contain illegal values, which are placed in your constrained type during deserialisation.

We have toyed with the idea of implementing a ReWrap () or similar method on these types, which would apply the business rules to make sure that the constrained type is valid, and adding Fable remoting option to allow us to call this method using reflection invoke if it exists. @Zaid-Ajaj does this seem like a reasonable addition to the library?

Roland

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

4 participants