-
Notifications
You must be signed in to change notification settings - Fork 321
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
Optional fields #1039
Optional fields #1039
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking Aeson could retain backwards compatibility if instead of adding an argument to liftToJSON
, a method liftToJSONWithOmit
could be added. It could have the default implementation liftToJSONOmit _ = liftToJSON
to preserve the behavior of people's existing instances. Similar additions to ToJSON2
and FromJSON1
, FromJSON2
could be made.
It's not worth it. There are barely any direct users of these https://hackage-search.serokell.io/?q=liftToJSON and arguably the ones who are (e.g. EDIT: In fact |
@phadej That all makes a lot of sense. Thanks for explaining the situation to me. (Also, I'll start defining |
tests/PropertyTH.hs
Outdated
@@ -130,10 +130,5 @@ templateHaskellTests = | |||
thOneConstructorToJSONDefault `sameAs` thOneConstructorToEncodingDefault | |||
, testProperty "OneConstructorTagged" $ | |||
thOneConstructorToJSONTagged `sameAs` thOneConstructorToEncodingTagged | |||
|
|||
#if !MIN_VERSION_base(4,16,0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un remove this?
-> (ConName :* TypeName :* Options :* FromArgs arity a) | ||
-> Object -> Parser (M1 i s f a) | ||
recordParseJSONImpl mdef parseVal (cname :* tname :* opts :* fargs) obj = | ||
handleMissingKey (M1 <$> mdef) $ do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use explicitParseFieldOmit
here?
* Adds 'omitField' to 'ToJSON' * Adds 'omittedField' to 'FromJSON'
@@ -840,6 +877,10 @@ parseFieldMaybe = (.:?) | |||
parseFieldMaybe' :: (FromJSON a) => Object -> Key -> Parser (Maybe a) | |||
parseFieldMaybe' = (.:!) | |||
|
|||
-- | Function variant of '.:?='. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@since
annotation, o nthis and omittedField2
etc.
d835b9d
to
f0c4476
Compare
- 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
Continuation of #1023