Skip to content
This repository has been archived by the owner on Nov 8, 2019. It is now read-only.

Thoth.Json: allow decoding of classes when value is null #132

Closed
0x53A opened this issue Mar 16, 2019 · 3 comments
Closed

Thoth.Json: allow decoding of classes when value is null #132

0x53A opened this issue Mar 16, 2019 · 3 comments

Comments

@0x53A
Copy link

0x53A commented Mar 16, 2019

I am using Fable Elmish React with ServerSideRendering.

My Model contains a mutable System.Collections.Generic.Dictionary as a cache.

On deserialization of the model I get an exception:

Error: Error at: `$.PageModel.SlabCache` I run into a `fail` decoder: Class types cannot be automatically deserialized: System.Collections.Generic.Dictionary`2[ebosYC.Domain.SlabId,Fable.Import.JS.Promise`1[System.Tuple`2[]]]

When I render the page on the server, I set the cache to null.

I haven't looked at the code of Thoth yet, but what would you think about emiting a special decoder that only accepts null when encountering an unknown class type?

@0x53A 0x53A changed the title Thoth.Json: allow decoding of classes Thoth.Json: allow decoding of classes when value is null Mar 16, 2019
@0x53A
Copy link
Author

0x53A commented Mar 16, 2019

So I think this would be solved by the new extra/custom serializers in Thoth.Json 3, but I couldn't yet update because of the breaking changes:

  1. Elmish.Bridge: Not compatible with Thoth.Json 3-beta Nhowka/Elmish.Bridge#17
  2. Powerpack / BrowserStorage (yes I know powerpack was split):

ERROR in ./.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs
Module Error (from ./node_modules/fable-loader/index.js):
c:/Projekte/ebos/ebosYC/.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs(18,40): (18,69) error FABLE: Cannot get type info of generic parameter T, please inline or inject a type resolver
 @ ./src/Client/Client.fs 21:0-302 173:16-54 188:4-42 194:4-42 201:52-92
 @ ./src/Client/App.fs
 @ ./src/Client/Client.fsproj
 @ multi ./src/Client/Client.fsproj ./src/Client/site.css

ERROR in ./.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs
Module Error (from ./node_modules/fable-loader/index.js):
c:/Projekte/ebos/ebosYC/.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs(22,28): (22,35) error FSHARP: The type 'Decoder' is not defined in 'Thoth.Json.Decode'. Maybe you want one of the following:
   DecoderException
 @ ./src/Client/Client.fs 21:0-302 173:16-54 188:4-42 194:4-42 201:52-92
 @ ./src/Client/App.fs
 @ ./src/Client/Client.fsproj
 @ multi ./src/Client/Client.fsproj ./src/Client/site.css

ERROR in ./.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs
Module Error (from ./node_modules/fable-loader/index.js):
c:/Projekte/ebos/ebosYC/.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs(32,42): (32,71) error FABLE: Cannot get type info of generic parameter T, please inline or inject a type resolver
 @ ./src/Client/Client.fs 21:0-302 173:16-54 188:4-42 194:4-42 201:52-92
 @ ./src/Client/App.fs
 @ ./src/Client/Client.fsproj
 @ multi ./src/Client/Client.fsproj ./src/Client/site.css

ERROR in ./.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs
Module Error (from ./node_modules/fable-loader/index.js):
c:/Projekte/ebos/ebosYC/.fable/Fable.PowerPack.3.0.0/BrowserStorage.fs(8,28): (8,35) error FSHARP: The type 'Decoder' is not defined in 'Thoth.Json.Decode'. Maybe you want one of the following:
   DecoderException
 @ ./src/Client/Client.fs 21:0-302 173:16-54 188:4-42 194:4-42 201:52-92
 @ ./src/Client/App.fs
 @ ./src/Client/Client.fsproj
 @ multi ./src/Client/Client.fsproj ./src/Client/site.css

@0x53A 0x53A closed this as completed Mar 16, 2019
@0x53A
Copy link
Author

0x53A commented Mar 17, 2019

I changed it to Dictionary<_,_> option and now it works (with 2.x).

As long as the value sent from the server is None, it correctly deserializes.

@MangelMaxime
Copy link
Owner

Indeed, when using 'T option if you send null the auto decoder will work. It was added for people using F# on client and server side.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants