aeson-compat 0.3.3.0 → 0.3.4.0
raw patch · 4 files changed
+26/−4 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGELOG.md +4/−0
- aeson-compat.cabal +2/−2
- src/Data/Aeson/Compat.hs +18/−1
- test/Tests.hs +2/−1
CHANGELOG.md view
@@ -1,3 +1,7 @@+# 0.3.4.0++- Add `NominalDiffTime` instances+ # 0.3.3.0 - Enable `PolyKinds` to generalize `Proxy`, `Tagged`, and `Const` instances.
aeson-compat.cabal view
@@ -1,9 +1,9 @@--- This file has been generated from package.yaml by hpack version 0.13.0.+-- This file has been generated from package.yaml by hpack version 0.14.0. -- -- see: https://github.com/sol/hpack name: aeson-compat-version: 0.3.3.0+version: 0.3.4.0 synopsis: Compatibility layer for aeson description: Compatibility layer for @aeson@ category: Web
src/Data/Aeson/Compat.hs view
@@ -61,7 +61,7 @@ import Data.Typeable (Typeable) #if !MIN_VERSION_aeson(0,10,0)-import Data.Time (Day, LocalTime, formatTime)+import Data.Time (Day, LocalTime, formatTime, NominalDiffTime) import Data.Time.Locale.Compat (defaultTimeLocale) import qualified Data.Aeson.Compat.Time as CompatTime #endif@@ -221,6 +221,23 @@ instance ToJSON LocalTime where toJSON = toJSON . T.pack . formatTime defaultTimeLocale "%FT%T%Q"++instance ToJSON NominalDiffTime where+ toJSON = Number . realToFrac+ {-# INLINE toJSON #-}+ +#if MIN_VERSION_aeson(0,10,0)+ toEncoding = Encoding . E.number . realToFrac+ {-# INLINE toEncoding #-}+#endif+ +-- | /WARNING:/ Only parse lengths of time from trusted input+-- since an attacker could easily fill up the memory of the target+-- system by specifying a scientific number with a big exponent like+-- @1e1000000000@.+instance FromJSON NominalDiffTime where+ parseJSON = withScientific "NominalDiffTime" $ pure . realToFrac+ {-# INLINE parseJSON #-} #endif -----------------------------------------------------------------------
test/Tests.hs view
@@ -9,7 +9,7 @@ import Data.List.NonEmpty (NonEmpty) import Data.Proxy (Proxy) import Data.Tagged (Tagged)-import Data.Time (Day, LocalTime)+import Data.Time (Day, LocalTime, NominalDiffTime) import Data.Version (Version) import Numeric.Natural (Natural) @@ -37,6 +37,7 @@ , testProperty "Proxy" $ roundtrip (undefined :: Proxy Int) , testProperty "Tagged" $ roundtrip (undefined :: Tagged Int Int) , testProperty "NonEmpty" $ roundtrip (undefined :: NonEmpty Int)+ , testProperty "NominalDiffTime" $ roundtrip (undefined :: NominalDiffTime) ] ]