Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Either uses value instead of contents #22

Open
peterbecich opened this issue Nov 25, 2023 · 2 comments
Open

Either uses value instead of contents #22

peterbecich opened this issue Nov 25, 2023 · 2 comments

Comments

@peterbecich
Copy link
Collaborator

peterbecich commented Nov 25, 2023

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

@peterbecich peterbecich changed the title Either uses key instead of contents Either uses value instead of contents Nov 25, 2023
@peterbecich
Copy link
Collaborator Author

I think related to #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant