agrafix / elm-bridge

Haskell: Derive Elm types from Haskell types
BSD 3-Clause "New" or "Revised" License
100 stars 27 forks source link

Dict serialization escape key string #48

Closed matsumonkie closed 4 years ago

matsumonkie commented 4 years ago

Hello,

First things first, thank you for this great lib, it helps a lot!! I have a minor question/issue regarding Dict serialization.

For Dict, encodeMap is used https://github.com/agrafix/elm-bridge/blob/0856922e8c2deabb1fecbfac9fe9eeee0c091913/src/Elm/Json.hs#L180 Because of encodeMap, if the key is a String, the json key will be escaped. eg:

{ "\"key\"" : "value" }

Is this voluntary? It seems more logical to use Json.Encode.dict to me but maybe I'm missing something...

bartavelle commented 4 years ago

You are right, it is pretty ugly! I'll try to take a look this week.

bartavelle commented 4 years ago

I pushed a quick fix for your exact use case. Unfortunately, a complete fix would be a bit more involved (with the new To/FromJSONKey mechanism in aeson).

Does that work for you?

matsumonkie commented 4 years ago

I just had to bump servant-elm to the latest 0.7.2 but it works perfectly!! Thank you so much for the quick patch, it helps a lot!!

bartavelle commented 4 years ago

Wow I did not realize servant-elm depended on elm-bridge!