Skip to content

Feature request: option to disallow deserializing union cases with private constructors #215

Description

@reinux

I do stuff like this:

type LocalPath = private LocalPath of string
with
  static member make (path: string) =
    if path.Contains ".."
    then failwith "String contains .."
    else LocalPath path
  member this.serialized =
    let (LocalPath path) = this
    path

module LocalPath =
  let (|LocalPath|) = fun (LocalPath f) -> f

This gets deserialized through reflection even though the constructor is marked private.

It would be nice to be able to disable this behavior so that it can be used viably as added security.

The current workaround is to use a custom JsonConverter and not let Fsharp.STJ unwrap anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions