on master help sign in
FromJSON and ToJSON instances for CTime.
commit42b690d0458ffe95128237a556bf539b3eb7064a authorDaniel Díaz <dhelta.diaz@gmail.com> dateFri 1 Sep 2017, 19:01 (9 years ago) parent475058c
2 files changed+11−1
Data/Aeson/Types/FromJSON.hs+4 Data/Aeson/Types/ToJSON.hs+7−1
Data/Aeson/Types/FromJSON.hs+4
@@ -109,6 +109,7 @@ import Data.Vector (Vector)
109109import Data.Version (Version, parseVersion)
110110import Data.Word (Word16, Word32, Word64, Word8)
111111import Foreign.Storable (Storable)
112+import Foreign.C.Types (CTime (..))
112113import GHC.Generics
113114import Numeric.Natural (Natural)
114115import Text.ParserCombinators.ReadP (readP_to_S)
@@ -1347,6 +1348,9 @@ instance FromJSON Word64 where
13471348instance FromJSONKey Word64 where
13481349 fromJSONKey = FromJSONKeyTextParser $ parseBoundedIntegralText "Word64"
13491350
1351+instance FromJSON CTime where
1352+ parseJSON = fmap CTime . parseJSON
1353+ {-# INLINE parseJSON #-}
13501354
13511355instance FromJSON Text where
13521356 parseJSON = withText "Text" pure
Data/Aeson/Types/ToJSON.hs+7−1
@@ -91,6 +91,7 @@ import Data.Vector (Vector)
9191import Data.Version (Version, showVersion)
9292import Data.Word (Word16, Word32, Word64, Word8)
9393import Foreign.Storable (Storable)
94+import Foreign.C.Types (CTime (..))
9495import GHC.Generics
9596import Numeric.Natural (Natural)
9697import qualified Data.Aeson.Encoding as E
@@ -1366,7 +1367,6 @@ instance ToJSONKey Int64 where
13661367 toJSONKey = toJSONKeyTextEnc E.int64Text
13671368 {-# INLINE toJSONKey #-}
13681369
1369−
13701370instance ToJSON Word where
13711371 toJSON = Number . fromIntegral
13721372 {-# INLINE toJSON #-}
@@ -1426,6 +1426,12 @@ instance ToJSONKey Word64 where
14261426 toJSONKey = toJSONKeyTextEnc E.word64Text
14271427 {-# INLINE toJSONKey #-}
14281428
1429+instance ToJSON CTime where
1430+ toJSON (CTime i) = toJSON i
1431+ {-# INLINE toJSON #-}
1432+
1433+ toEncoding (CTime i) = toEncoding i
1434+ {-# INLINE toEncoding #-}
14291435
14301436instance ToJSON Text where
14311437 toJSON = String