deriving-aeson 0.1.2 → 0.2
raw patch · 5 files changed
+46/−7 lines, 5 filesdep ~aesonPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson
API changes (from Hackage documentation)
- Deriving.Aeson: data ConstrctorTagModifier t
- Deriving.Aeson: instance forall k (f :: k) (xs :: [*]). (Deriving.Aeson.StringModifier f, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.ConstrctorTagModifier f : xs)
- Deriving.Aeson: instance forall k (t :: k) a. (Deriving.Aeson.AesonOptions t, GHC.Generics.Generic a, Data.Aeson.Types.Class.GToJSON Data.Aeson.Types.Generic.Zero (GHC.Generics.Rep a)) => Data.Aeson.Types.ToJSON.ToJSON (Deriving.Aeson.CustomJSON t a)
+ Deriving.Aeson: data ConstructorTagModifier t
+ Deriving.Aeson: data SumObjectWithSingleField
+ Deriving.Aeson: data SumTaggedObject t c
+ Deriving.Aeson: data SumTwoElemArray
+ Deriving.Aeson: data SumUntaggedValue
+ Deriving.Aeson: instance (GHC.TypeLits.KnownSymbol t, GHC.TypeLits.KnownSymbol c, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.SumObjectWithSingleField : xs)
+ Deriving.Aeson: instance (GHC.TypeLits.KnownSymbol t, GHC.TypeLits.KnownSymbol c, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.SumTaggedObject t c : xs)
+ Deriving.Aeson: instance (GHC.TypeLits.KnownSymbol t, GHC.TypeLits.KnownSymbol c, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.SumTwoElemArray : xs)
+ Deriving.Aeson: instance (GHC.TypeLits.KnownSymbol t, GHC.TypeLits.KnownSymbol c, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.SumUntaggedValue : xs)
+ Deriving.Aeson: instance forall k (f :: k) (xs :: [*]). (Deriving.Aeson.StringModifier f, Deriving.Aeson.AesonOptions xs) => Deriving.Aeson.AesonOptions (Deriving.Aeson.ConstructorTagModifier f : xs)
+ Deriving.Aeson: instance forall k (t :: k) a. (Deriving.Aeson.AesonOptions t, GHC.Generics.Generic a, Data.Aeson.Types.Class.GToJSON Data.Aeson.Types.Generic.Zero (GHC.Generics.Rep a), Data.Aeson.Types.Class.GToEncoding Data.Aeson.Types.Generic.Zero (GHC.Generics.Rep a)) => Data.Aeson.Types.ToJSON.ToJSON (Deriving.Aeson.CustomJSON t a)
+ Deriving.Aeson.Stock: type Vanilla = CustomJSON '[]
Files
- CHANGELOG.md +7/−0
- README.md +1/−1
- deriving-aeson.cabal +6/−2
- src/Deriving/Aeson.hs +28/−4
- src/Deriving/Aeson/Stock.hs +4/−0
CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for deriving-aeson +## 0.2++* Added `Sum*` for changing the encoding of variants+* Added `Vanilla = CustomJSON '[]`+* Renamed `ContructorTagModifier` to `ConstructorTagModifier`+* Added `toEncoding` implementation to `CustomJSON`+ ## 0.1.2 * Reexported `CustomJSON(..)` from `Deriving.Aeson.Stock`
README.md view
@@ -6,7 +6,7 @@ [](https://discord.gg/DG93Tgs) This package provides a newtype wrapper where you can customise-[aeson](https://hackage,haskell.org/package/aeson)'s generic methods using a+[aeson](https://hackage.haskell.org/package/aeson)'s generic methods using a type-level interface, which synergises well with DerivingVia. ```haskell
deriving-aeson.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: deriving-aeson-version: 0.1.2+version: 0.2 synopsis: Type driven generic aeson instance customisation description: This package provides a newtype wrapper with FromJSON/ToJSON instances customisable via a phantom type parameter.@@ -14,11 +14,15 @@ category: JSON, Generics extra-source-files: CHANGELOG.md, README.md +source-repository head+ type: git+ location: https://github.com/fumieval/deriving-aeson.git+ library exposed-modules: Deriving.Aeson Deriving.Aeson.Stock- build-depends: base >= 4.12 && <5, aeson+ build-depends: base >= 4.12 && <5, aeson >= 1.3 && <1.5 hs-source-dirs: src default-language: Haskell2010 ghc-options: -Wall
src/Deriving/Aeson.hs view
@@ -13,10 +13,15 @@ module Deriving.Aeson ( CustomJSON(..) , FieldLabelModifier- , ConstrctorTagModifier+ , ConstructorTagModifier , OmitNothingFields , TagSingleConstructors , NoAllNullaryToStringTag+ -- * Sum encoding+ , SumTaggedObject+ , SumUntaggedValue+ , SumObjectWithSingleField+ , SumTwoElemArray -- * Name modifiers , StripPrefix , CamelToKebab@@ -45,15 +50,17 @@ parseJSON = (coerce `asTypeOf` fmap CustomJSON) . genericParseJSON (aesonOptions @t) {-# INLINE parseJSON #-} -instance (AesonOptions t, Generic a, GToJSON Zero (Rep a)) => ToJSON (CustomJSON t a) where+instance (AesonOptions t, Generic a, GToJSON Zero (Rep a), GToEncoding Zero (Rep a)) => ToJSON (CustomJSON t a) where toJSON = genericToJSON (aesonOptions @t) . unCustomJSON {-# INLINE toJSON #-}+ toEncoding = genericToEncoding (aesonOptions @t) . unCustomJSON+ {-# INLINE toEncoding #-} -- | Function applied to field labels. Handy for removing common record prefixes for example. data FieldLabelModifier t -- | Function applied to constructor tags which could be handy for lower-casing them for example.-data ConstrctorTagModifier t+data ConstructorTagModifier t -- | Record fields with a Nothing value will be omitted from the resulting object. data OmitNothingFields@@ -90,6 +97,11 @@ instance StringModifier CamelToSnake where getStringModifier = camelTo2 '_' +data SumTaggedObject t c+data SumUntaggedValue+data SumObjectWithSingleField+data SumTwoElemArray+ -- | Reify 'Options' from a type-level list class AesonOptions xs where aesonOptions :: Options@@ -103,7 +115,7 @@ instance (StringModifier f, AesonOptions xs) => AesonOptions (FieldLabelModifier f ': xs) where aesonOptions = (aesonOptions @xs) { fieldLabelModifier = getStringModifier @f } -instance (StringModifier f, AesonOptions xs) => AesonOptions (ConstrctorTagModifier f ': xs) where+instance (StringModifier f, AesonOptions xs) => AesonOptions (ConstructorTagModifier f ': xs) where aesonOptions = (aesonOptions @xs) { constructorTagModifier = getStringModifier @f } instance AesonOptions xs => AesonOptions (TagSingleConstructors ': xs) where@@ -111,3 +123,15 @@ instance AesonOptions xs => AesonOptions (NoAllNullaryToStringTag ': xs) where aesonOptions = (aesonOptions @xs) { allNullaryToStringTag = False }++instance (KnownSymbol t, KnownSymbol c, AesonOptions xs) => AesonOptions (SumTaggedObject t c ': xs) where+ aesonOptions = (aesonOptions @xs) { sumEncoding = TaggedObject (symbolVal (Proxy @ t)) (symbolVal (Proxy @ t)) }++instance (KnownSymbol t, KnownSymbol c, AesonOptions xs) => AesonOptions (SumUntaggedValue ': xs) where+ aesonOptions = (aesonOptions @xs) { sumEncoding = UntaggedValue }++instance (KnownSymbol t, KnownSymbol c, AesonOptions xs) => AesonOptions (SumObjectWithSingleField ': xs) where+ aesonOptions = (aesonOptions @xs) { sumEncoding = ObjectWithSingleField }++instance (KnownSymbol t, KnownSymbol c, AesonOptions xs) => AesonOptions (SumTwoElemArray ': xs) where+ aesonOptions = (aesonOptions @xs) { sumEncoding = ObjectWithSingleField }
src/Deriving/Aeson/Stock.hs view
@@ -5,6 +5,7 @@ ( Prefixed , PrefixedSnake , Snake+ , Vanilla -- * Reexports , CustomJSON(..) , FromJSON@@ -21,3 +22,6 @@ -- | Convert from CamelCase to snake_case type Snake = CustomJSON '[FieldLabelModifier CamelToSnake]++-- | No customisation+type Vanilla = CustomJSON '[]