aeson-possible 0.1.0.0 → 0.1.0.1
raw patch · 4 files changed
+56/−5 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +5/−0
- README.md +46/−0
- aeson-possible.cabal +4/−4
- test/Main.hs +1/−1
CHANGELOG.md view
@@ -1,5 +1,10 @@ # Revision history for aeson-possible +## 0.1.0.1 -- 2024-06-27++* Fix errors in documentation on use of Aeson `Options`+* Update package category+ ## 0.1.0.0 -- 2024-01-23 * First version. Released on an unsuspecting world.
+ README.md view
@@ -0,0 +1,46 @@+# aeson-possible++[](https://github.com/jonathanjouty/aeson-possible/actions/workflows/ci-haskell.yml)++Three-valued possible types for use with `aeson`.++Useful for use in PATCH endpoints: use in records which have `ToJSON` and+`FromJSON` instances.++Inspired by the [`possible`](https://hackage.haskell.org/package/possible)+package, but additionally provides To/FromJSON instances using `aeson >= 2.2`'s+`omitField` and `omittedField` machinery.++## Usage++Use `Possible a` in your records++```hs+data MyRecord = MyRecord+ { myBool :: Possible Bool+ , myInt :: Possible Int+ , myStr :: Possible Text+ }+ deriving (Generic)+```++and then make sure to use the correct options if you are generically deriving+your To/FromJSON instances:++```hs+instance ToJSON MyRecord where+ toJSON = genericToJSON $ defaultOptions{omitNothingFields = True}++instance FromJSON MyRecord where+ parseJSON = genericParseJSON $ defaultOptions{allowOmittedFields = True}+```++Note that `omitNothingFields` affects `ToJSON`, and `allowOmittedFields`+affects `FromJSON`. You can, of course, also set both to `True`.++If you are creating instances any other way, see `aeson`'s documentation for+how to make use of `omitField` and `omittedField`.++_Caveat:_ if you are using `Possible` outside a record, even a `Missing` value+will likely be encoded as `null` (_e.g._ if you have a list of `Possible`+values).
aeson-possible.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: aeson-possible-version: 0.1.0.0+version: 0.1.0.1 synopsis: Possible values for aeson description: Three-valued possible types for use with aeson. Useful for use in PATCH endpoints.@@ -8,10 +8,10 @@ license: BSD-3-Clause license-file: LICENSE author: Jonathan Jouty-maintainer: me@jonathanjouty.com-category: Data+maintainer: Jonathan Jouty <me@jonathanjouty.com>+category: Data, Web, JSON build-type: Simple-extra-doc-files: CHANGELOG.md+extra-doc-files: CHANGELOG.md, README.md tested-with: GHC == 9.4 || == 9.6
test/Main.hs view
@@ -73,7 +73,7 @@ deriving stock (Show, Generic, Eq) instance FromJSON TestData where- parseJSON = genericParseJSON $ defaultOptions{omitNothingFields = True}+ parseJSON = genericParseJSON $ defaultOptions{allowOmittedFields = True} instance ToJSON TestData where toJSON = genericToJSON $ defaultOptions{omitNothingFields = True}