question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can not serialize/deserialize type with "internal" or "private" modifier

See original GitHub issue

Hello. When I try to serialize/deserialize Person, I have an exception

FSharp.Json.JsonSerializationError: ‘Failed to serialize, must be one of following types: record, map, array, list, tuple, union. Type is: Person.’

But if I remove internal modifier for Person, the code works fine


type internal Person = {

    [<JsonField("name")>]
    Name: string

    [<JsonField("age")>]
    Age: int
}

[<EntryPoint>]
let main argv =
    let person = { Name = "John"; Age = 42 }
    let json = Json.serialize person
    0

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
bzuu-iccommented, Nov 27, 2020

I am mostly thinking along the lines of adding this as a configuration option which can be used with the serializeEx and deserializeEx methods. This allows you to use it only in those circumstances where you actually need it and it makes it a very deliberate choice. For all other cases you can keep the more sensible default.

0reactions
bartelinkcommented, Nov 26, 2020

I think this should not be the default behaviour indeed

I get that; I’ve been bitten by it too, and it is can be very frustrating, but the fact that this would place this lib on its own in terms of opting people into the cost of private reflection.

Flipping a default like this can be considered a breaking change, depending on how you look at it.

(Its also possible that there’s been perf optimization work done to special case the loading such that you only pay extra cost when they are private - that would probably be something that people would be less surprised by, if it were the case…)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not serialize/deserialize type with "internal" or "private ...
Hello. When I try to serialize/deserialize Person, I have an exception FSharp.Json.JsonSerializationError: 'Failed to serialize, must be one ...
Read more >
Making a property deserialize but not serialize with json.net
Apply a [JsonIgnore] attribute to the property that you do not want to be serialized. Add an alternate, private property setter to the...
Read more >
How to not shoot yourself in the foot when working with ...
The serialization constructor in an unsealed class has an access modifier 'private'; Do not declare the serialization constructor with ...
Read more >
Custom serialization and deserialization contracts
Learn how to write your own contract resolution logic to customize the JSON contract for a type.
Read more >
Serialization and Deserialization in Java with Example
A Serializable class can declare its own UID explicitly by ... It is also recommended to use private modifier for UID since it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found