Skip to content

Fix Generic encoding of records with single Maybe field#532

Merged
bergmark merged 1 commit into
haskell:masterfrom
Lysxia:bug-single-maybe
Apr 3, 2017
Merged

Fix Generic encoding of records with single Maybe field#532
bergmark merged 1 commit into
haskell:masterfrom
Lysxia:bug-single-maybe

Conversation

@Lysxia
Copy link
Copy Markdown
Collaborator

@Lysxia Lysxia commented Mar 28, 2017

With

data Single = Single { f :: Maybe Int } deriving Generic

instance ToJSON Single where
  toJSON = genericToJSON defaultOptions{omitNothingFields=True,unwrapUnaryRecords=True}

We have:

encode (Nothing :: Maybe Int) = "null"
encode (Just 1 :: Maybe Int) = "1"

Yet:

encode (Single Nothing) = "{}"
encode (Single (Just 1)) = "1"

That is, if the field is Nothing, then the record is not being unwrapped and omitNothingFields applies instead, producing an empty object.

@Lysxia Lysxia force-pushed the bug-single-maybe branch from 7842a26 to af6adaf Compare March 29, 2017 04:27
@bergmark
Copy link
Copy Markdown
Collaborator

bergmark commented Apr 2, 2017

Looks great, thanks!

To be safe I think I'll include this in 1.2.0.0. Do you have a preferred order for merging your PR's?

@Lysxia
Copy link
Copy Markdown
Collaborator Author

Lysxia commented Apr 2, 2017

Actually I fixed this in the refactoring at the same time (which is how I came across the issue of this PR), so I would merge the refactoring (#524) before this one which would then only provide the test.

#524, #532, and finally #522 (after one last change to do I mentioned over there).

@bergmark
Copy link
Copy Markdown
Collaborator

bergmark commented Apr 3, 2017

This has some merge conflicts now

@Lysxia Lysxia force-pushed the bug-single-maybe branch from af6adaf to f06d2b1 Compare April 3, 2017 19:20
@Lysxia
Copy link
Copy Markdown
Collaborator Author

Lysxia commented Apr 3, 2017

Rebased. This now just adds the regression test case.

@bergmark
Copy link
Copy Markdown
Collaborator

bergmark commented Apr 3, 2017

Great!

@bergmark bergmark merged commit 7b8d3ce into haskell:master Apr 3, 2017
@bergmark bergmark added this to the 1.2.0.0 milestone Apr 16, 2017
@Lysxia Lysxia deleted the bug-single-maybe branch June 10, 2018 12:06
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

Successfully merging this pull request may close these issues.

2 participants