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

omitNothingFields is broken #306

Closed
akhra opened this issue Oct 18, 2015 · 2 comments
Closed

omitNothingFields is broken #306

akhra opened this issue Oct 18, 2015 · 2 comments

Comments

@akhra
Copy link

akhra commented Oct 18, 2015

data Foo = Foo { bar :: Maybe Int } deriving Show
$(deriveJSON defaultOptions{omitNothingFields=True} ''Foo)

Error: Couldn't match expected type `Text' with actual type `Builder'
In the first argument of `(.=)', namely `text (pack "bar")'
In the first argument of `(<$>)', namely `(text (pack "bar") .=)'

Maybe fallout related to #287? But here's the weird thing, I actually discovered this first:

type Synonym = Maybe Int
data Foo = Foo { bar :: Synonym } deriving Show
$(deriveJSON defaultOptions{omitNothingFields=True} ''Foo)

>>> decode "{}" :: Maybe Foo
Just (Foo {bar = Nothing})
>>> encode $ Foo Nothing
"{\"bar\":null}"

omitNothingFields wasn't omitting them. I removed the type for sanity checking, and it exploded! (I was working with more complex types, but this simple example shows the same behavior.) So this might be two bugs; for some reason a synonym prevents the compile failure, but still has wrong behavior.

Everything works fine when omitNothingFields=False.

@basvandijk
Copy link
Member

The Couldn't match expected type 'Text' with actual type 'Builder' error is a duplicate of #293 which is fixed in HEAD.

I will look into why Nothing fields aren't omitted in:

encode $ Foo Nothing
"{\"bar\":null}"

@bergmark
Copy link
Collaborator

Nothing fields are omitted on master so I'll close this.

λ> encode $ Foo Nothing
"{}"

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

3 participants