haskell / haskell/aeson

Surprising behavior with Generic deriving

Open
#1,158 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
1.3k
Forks
336
Avg merge
3d 7h
Merged PRs (30d)
4

Description

I am building out a Servant api containing the following type:

```
data NotVerified = NotVerified
deriving stock (Generic)
deriving anyclass (ToJSON, FromJSON)

data NotVerifiedResponse = NotVerifiedResponse { errorCode :: NotVerified }
deriving stock (Generic)
deriving anyclass (ToJSON, FromJSON)
```

Strangely, if I JSON encode the NotVerifiedResponse I get

```
encode $ NotVerifiedResponse { errorCode = NotVerified }
"{\"errorCode\":[]}"
```

I'd expect to see

```
"{\"errorCode\":\"NotVerified\"}"
```

I am using GHC 9.10.3 and aeson 2.2.3.0

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.