Can not serialize/deserialize type with "internal" or "private" modifier
See original GitHub issueHello. 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:
- Created 4 years ago
- Comments:7 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am mostly thinking along the lines of adding this as a configuration option which can be used with the
serializeEx
anddeserializeEx
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.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…)