Skip to content

Surprising behavior with Generic deriving #1158

@alexbiehl

Description

@alexbiehl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions