Bolero icon indicating copy to clipboard operation
Bolero copied to clipboard

Add support for IJsonDocument ser/deser (FSharp.Data)

Open jkone27 opened this issue 3 years ago • 5 comments

One or more errors occurred. (Deserialization of interface types is not supported. Type 'FSharp.Data.Runtime.BaseTypes.IJsonDocument'. Path: $ | LineNumber: 0 | BytePositionInLine: 1.)

JsonProvider from FSharp.Data needs this type if it's used to build shared DTOs between client and server.

is it possible to support this specific interface type serialization/deserialization ?

would be handy

jkone27 avatar Nov 10 '21 17:11 jkone27

This isn't a Bolero issue - this is a usercode issue that's cropping up at the JSON (de)serialization layer.
You can't deserialize interface types because they're not concrete implementations of something, just a shape, and lots of contradictory things might implement that interface.

laenas avatar Nov 12 '21 10:11 laenas

Yeah it's not an issue, it is a suggestion. if it needs to be a concrete type it can be JsonValue. F# data serialization is quite commonly used if using type providers, so i thought could be useful to add.

jkone27 avatar Nov 14 '21 14:11 jkone27

But that forces a dependency on FSharp.Data, which is both huge and unnecessary. Bolero already has opinions on JSON serialization - via FSharp.SystemTextJson.

Nothing is blocking individual consumers of Bolero from using the JSON Type Provider in their code - it's just not something necessary for all Bolero consumers to have.

laenas avatar Nov 14 '21 17:11 laenas

Ah yes true you are right, could be a separate assembly/library. To avoid lock in dependency

jkone27 avatar Nov 15 '21 11:11 jkone27

Yes, in fact this is something that would be useful for all System.Text.Json users, not just Bolero. A library FSharp.Data.SystemTextJson that provides a System.Text.Json converter for JsonValue would be the way to go I think.

Tarmil avatar Nov 16 '21 10:11 Tarmil