-
Notifications
You must be signed in to change notification settings - Fork 323
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
Derived ToJSON1 instance does not respect omitNothingFields = True #687
Comments
Indeed, it seems that this option currently only works for In particular, Would it work for you to use |
I'm really not sure how to do it in a way that's re-usable.
fails to compile with
similarly for Encoding. I really have no idea how to direct derivation of |
Can you try -- When going through Generic, maybe you don't need the ...1 variant.
newtype AesonWrapper a = AesonWrapper { unAesonWrapper :: a }
-- You can only solve `GToJSON` and `GToEncoding` constraints for concrete `a`, so as long as it's a type variable, the constraints have to be explicit like this.
instance (Generic a, GToJSON (Rep a), GToEncoding (Rep a)) => ToJSON (AesonWrapper a) where
...
-- same as before
data C a = ...
deriving via (AesonWrapper (C a)) instance ToJSON a => ToJSON (C a)
-- does the "via" go here or at the end? |
Ah thanks! Yes, you are right I can just use the basic wrapper. (My brain is a little fuzzy at the moment...) This makes the test pass
Now, I originally switched to ToJSON1 because for fixpoint types like |
Ok, it even seems to work recursively! https://gist.github.com/ejconlon/a017e2dc7f0482c26b0d26b0efd9e22d My final question: Should we put a warning in the |
Problems with |
What do you think about this warning in the documentation for
|
sounds good!
…On Thu, 7 Mar 2019 at 01:37, Eric Conlon ***@***.***> wrote:
What do you think about this warning in the documentation for
genericLiftToJSON and genericLiftToEncoding:
Please note that this does not obey the omitNothingFields option of the
provided Options. If this is an issue, please derive ToJSON instead of
ToJSON1.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#687 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAGJSftOQdp3uUur8GhfTDv95H6b_iB2ks5vUF8vgaJpZM4bhUck>
.
|
With #1039 we should be able to fix I'll add tests for this issue to verify they do. |
- Add combinators for using omit* stuff in manually written instances - Add Manual tests - Cleanup OptionalFields.Common - Fix TH and Generics - Add combinators ToJSON1/2 and FromJSON1/2 - Const, Identity, Tagged and other newtypes - Fix #687. ToJSON1 respects omitting fields - Fix #571. Introduce allowOmittedFields to Generics/TH options. - Resolve #792. () and Proxy can be omitted
- Add combinators for using omit* stuff in manually written instances - Add Manual tests - Cleanup OptionalFields.Common - Fix TH and Generics - Add combinators ToJSON1/2 and FromJSON1/2 - Const, Identity, Tagged and other newtypes - Fix #687. ToJSON1 respects omitting fields - Fix #571. Introduce allowOmittedFields to Generics/TH options. - Resolve #792. () and Proxy can be omitted
- Add combinators for using omit* stuff in manually written instances - Add Manual tests - Cleanup OptionalFields.Common - Fix TH and Generics - Add combinators ToJSON1/2 and FromJSON1/2 - Const, Identity, Tagged and other newtypes - Fix #687. ToJSON1 respects omitting fields - Fix #571. Introduce allowOmittedFields to Generics/TH options. - Resolve #792. () and Proxy can be omitted
- Add combinators for using omit* stuff in manually written instances - Add Manual tests - Cleanup OptionalFields.Common - Fix TH and Generics - Add combinators ToJSON1/2 and FromJSON1/2 - Const, Identity, Tagged and other newtypes - Fix haskell#687. ToJSON1 respects omitting fields - Fix haskell#571. Introduce allowOmittedFields to Generics/TH options. - Resolve haskell#792. () and Proxy can be omitted
For an instance
with a simple deriving via newtype wrapper
AesonWrapper1
I am seeing the valueC 1 Nothing
serialize withnull
See https://gist.github.com/ejconlon/30dc50b183a0f72501c3e49ce57cae52 for a self-contained repro.
The text was updated successfully, but these errors were encountered: