Mismatch in format used by elm-bridge and Aeson
- 主要語言
- Elm
- 星號
- 107
- 分支
- 28
- PR 合併指標
- 30 天內沒有已合併 PR
描述
My setup is that I have a websocket server running in Haskell, accepting commands encoded into JSON by elm-bridge's encoders on the client-side, and decoded by Aeson on the server-side.
On the server, in Haskell I have my data types defined as follows:
```haskell
{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module Domain.Data where
import GHC.Generics
import Data.Aeson
data WebSocketMessage = WebSocketMessage String deriving (Eq, Show, Generic, ToJSON, FromJSON)
data WebSocketCommand = WebSocketCommand Command deriving (Eq, Show, Generic, ToJSON, FromJSON)
data Id = Id String deriving (Eq, Show, Ord, Generic, ToJSON, FromJSON)
data EditDone = EditDone Id DoneState DoneState deriving (Eq, Show, Generic, ToJSON, FromJSON)
data DoneState = Done | NotDone deriving (Eq, Show, Generic, ToJSON, FromJSON)
data Command
= EditDoneCommand EditDone
| OtherCommands
```
and these are decoded in the server via:
```haskell
let mCmd :: Maybe WebSocketCommand = Json.decode msg
```
Note that I'm using the Generic, ToJSON, and FromJSON automatic derivations for the server-side decoding via Aeson.
Also in Haskell I'm executing elm-bridge, like so:
```haskell
{-# LANGUAGE TemplateHaskell #-}
import Elm.Derive
import Elm.Module
import Data.Proxy
import Domain.Data
deriveElmDef defaultOptions ''EditDone
deriveElmDef defaultOptions ''Command
deriveElmDef defaultOptions ''Id
deriveElmDef defaultOptions ''DoneState
main :: IO ()
main = do
putStrLn $ makeElmModule "Domain.Data"
[ DefineElm (Proxy :: Proxy EditDone)
, DefineElm (Proxy :: Proxy Command)
, DefineElm (Proxy :: Proxy Id)
, DefineElm (Proxy :: Proxy DoneState)
```
Note that I'm only running "deriveElmDef" as the Aeson derivations are already done separately. This took a bit of working out on my part as I don't think it's documented, so it may well be that I got this bit wrong; I couldn't get my program to compile any other way though!
Right, now to the meat; I added some tracing to my server and I can see that I receive JSON in the form:
```json
{"EditDoneCommand":["foo","NotDone","Done"]}
```
But when Aeson decodes it I get a Nothing. So I added an output for Aeson's encoding, and it turns out that Aeson outputs a different format:
```json
{"tag":"EditDoneCommand","contents":["foo","NotDone","Done"]}
```
Which looks like a longer form.
Given that I'm not familiar with Aeson, have I misconfigured something in my enthusiasm to get the thing compiling? Do you know how I can remedy this situation?
Thanks in advance for any advice!
PS. I have elm-bridge 0.4.0 and Aeson 0.11.2.1 installed.
貢獻指南
這個儲存庫沒有索引到貢獻指南
評估
這個 Issue 還沒有評估資料。