packages feed

aeson-via 0.2.1 → 0.2.2

raw patch · 5 files changed

+48/−34 lines, 5 filesdep ~textsetup-changedPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: text

API changes (from Hackage documentation)

Files

README.md view
@@ -1,5 +1,3 @@ # aeson-via -[![CircleCI](https://circleci.com/gh/ejconlon/aeson-via/tree/master.svg?style=svg)](https://circleci.com/gh/ejconlon/aeson-via/tree/master)- Wrappers to derive-via Aeson ToJSON/FromJSON typeclasses with typeclass-directed configuration.
− Setup.hs
@@ -1,2 +0,0 @@-import Distribution.Simple-main = defaultMain
aeson-via.cabal view
@@ -1,13 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.0.+-- This file has been generated from package.yaml by hpack version 0.35.2. -- -- see: https://github.com/sol/hpack------ hash: d810620276cd1066523e2e1543d06ac95aafc53f99394226b2768f5a025d3346  name:           aeson-via-version:        0.2.1+version:        0.2.2 synopsis:       Wrappers to derive-via Aeson ToJSON/FromJSON typeclasses description:    Please see the README on GitHub at <https://github.com/ejconlon/aeson-via#readme> category:       Data@@ -39,7 +37,7 @@     , aeson-casing ==0.2.*     , base >=4.12 && <5     , newtype-generics >=0.5 && <0.7-    , text >=1.2 && <2.0+    , text >=1.2 && <2.1   default-language: Haskell2010  test-suite aeson-via-test@@ -58,5 +56,5 @@     , newtype-generics >=0.5 && <0.7     , tasty >=1.2 && <1.5     , tasty-hunit ==0.10.*-    , text >=1.2 && <2.0+    , text >=1.2 && <2.1   default-language: Haskell2010
src/AesonVia.hs view
@@ -1,6 +1,7 @@ {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}  -- | Wrappers to control generic 'ToJSON' and 'FromJSON' derivation with deriving-via.@@ -11,11 +12,23 @@   , AesonTag (..)   , HasJSONOptions (..)   , HasTagPrefix (..)-  ) where+  )+where  import Control.Newtype.Generics (Newtype, O, pack, unpack)-import Data.Aeson (FromJSON (..), GFromJSON, GToEncoding, GToJSON, Options (..), ToJSON (..), Zero, defaultOptions,-                   genericParseJSON, genericToEncoding, genericToJSON)+import Data.Aeson+  ( FromJSON (..)+  , GFromJSON+  , GToEncoding+  , GToJSON+  , Options (..)+  , ToJSON (..)+  , Zero+  , defaultOptions+  , genericParseJSON+  , genericToEncoding+  , genericToJSON+  ) import Data.Aeson.Casing (aesonPrefix, snakeCase) import Data.Proxy (Proxy (..)) import Data.Text (Text)@@ -26,20 +39,21 @@ -- Options  recordOptions :: Options-recordOptions = (aesonPrefix snakeCase) { omitNothingFields = True }+recordOptions = (aesonPrefix snakeCase) {omitNothingFields = True}  tagOptions :: Text -> Options tagOptions prefix =   let prefixLen = Text.length prefix-  in defaultOptions-      { allNullaryToStringTag = True-      , constructorTagModifier = snakeCase . drop prefixLen-      }+  in  defaultOptions+        { allNullaryToStringTag = True+        , constructorTagModifier = snakeCase . drop prefixLen+        }  newtypeOptions :: Options-newtypeOptions = defaultOptions-  { unwrapUnaryRecords = True-  }+newtypeOptions =+  defaultOptions+    { unwrapUnaryRecords = True+    }  -- Has classes @@ -56,7 +70,7 @@ -- Wrappers  -- | Generic deriving ToJSON/FromJSON via this uses 'HasTagPrefix' to turn 'Bounded' 'Enum' datatypes into enumerated strings.-newtype AesonTag a = AesonTag { unAesonTag :: a }+newtype AesonTag a = AesonTag {unAesonTag :: a}  instance HasTagPrefix a => HasJSONOptions (AesonTag a) where   getJSONOptions _ = tagOptions (getTagPrefix (Proxy :: Proxy a))@@ -69,7 +83,7 @@   parseJSON = (AesonTag <$>) . genericParseJSON (getJSONOptions (Proxy :: Proxy (AesonTag a)))  -- | Generic deriving ToJSON/FromJSON via this removes the common field name prefix in the encoding.-newtype AesonRecord a = AesonRecord { unAesonRecord :: a }+newtype AesonRecord a = AesonRecord {unAesonRecord :: a}  instance HasJSONOptions (AesonRecord a) where   getJSONOptions _ = recordOptions@@ -82,7 +96,7 @@   parseJSON = (AesonRecord <$>) . genericParseJSON (getJSONOptions (Proxy :: Proxy (AesonRecord a)))  -- | Generic deriving ToJSON/FromJSON via this yields an encoding equivalent to the wrapped type.-newtype AesonNewtype n o = AesonNewtype { unAesonNewtype :: n }+newtype AesonNewtype n o = AesonNewtype {unAesonNewtype :: n}  instance HasJSONOptions (AesonNewtype n o) where   getJSONOptions _ = newtypeOptions
test/Main.hs view
@@ -4,7 +4,8 @@  module Main   ( main-  ) where+  )+where  import AesonVia (AesonNewtype (..), AesonRecord (..), AesonTag (..), HasTagPrefix (..)) import Control.Newtype.Generics (Newtype)@@ -16,13 +17,14 @@  newtype Author = Author   { _authorWrapped :: String-  } deriving (Eq, Show, Generic)-    deriving (ToJSON, FromJSON) via (AesonNewtype Author String)+  }+  deriving (Eq, Show, Generic)+  deriving (ToJSON, FromJSON) via (AesonNewtype Author String)  instance Newtype Author -data Category =-    CategoryNews+data Category+  = CategoryNews   | CategoryOpinion   | CategoryLies   deriving (Eq, Show, Generic)@@ -35,8 +37,9 @@   { _articleTitle :: String   , _articleAuthor :: Author   , _articleCategory :: Category-  } deriving (Eq, Show, Generic)-    deriving (ToJSON, FromJSON) via (AesonRecord Article)+  }+  deriving (Eq, Show, Generic)+  deriving (ToJSON, FromJSON) via (AesonRecord Article)  testSomething :: TestTree testSomething = testCase "something" $ do@@ -46,6 +49,9 @@   actual @?= expected  main :: IO ()-main = defaultMain $ testGroup "AesonVia"-  [ testSomething-  ]+main =+  defaultMain $+    testGroup+      "AesonVia"+      [ testSomething+      ]