Skip to content

Either uses value instead of contents #22

@peterbecich

Description

@peterbecich

Unsure if this belongs to argonaut-aeson-generic, or Argonaut.

Here's a few test datatypes in PureScript:

data TestSum
  = Nullary
  | Bool Boolean
  | Int Int
  | Number Number

data TestData
  = TMaybe (Maybe TestSum)
  | TEither String

newtype Foo = Foo
  { _fooE :: Either String Int
  , _fooTestSum :: TestSum
  , _fooTestData :: TestData
  }

and test value:

testFoo = Foo
  { _fooE: Left "foo"
  , _fooTestSum: Nullary
  , _fooTestData: TEither "foo"
  }

Options are:

ops :: Options
ops = Options
  { sumEncoding: TaggedObject { tagFieldName: "tag", contentsFieldName: "contents" }
  , tagSingleConstructors: true
  , allNullaryToStringTag: true
  }

Encoding to JSON:

z = genericEncodeAeson ops testFoo
log $ stringify $ z

the result is:


{
  "_fooTestSum": {
    "tag": "Nullary"
  },
  "_fooTestData": {
    "tag": "TEither",
    "contents": "foo"
  },
  "_fooE": {
    "tag": "Left",
    "value": "foo"
  }
}

The made-up type TEither correctly uses "contents". The standard library Either uses "value".

I think this breaks compatibility with Aeson on the Haskell side, which uses "contents" for all datatypes.

It looks like Argonaut is picking up the encoding options from somewhere else, for the Either.

I am trying to update Purescript Bridge using argonaut-aeson-generic: eskimor/purescript-bridge#89

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions