on master help sign in
Merge branch 'numeric-natural-instances' of https://github.com/mrkkrp/aeson
commit05249ea63c349f8c31f94b2a17da55568a58a23b authorBas van Dijk <v.dijk.bas@gmail.com> dateWed 9 Dec 2015, 22:33 (11 years ago) parentd3f0f5c477036c
1 file changed+15−1
Data/Aeson/Types/Instances.hs+15−1
Data/Aeson/Types/Instances.hs+15−1
@@ -106,7 +106,9 @@ import qualified Data.Vector.Primitive as VP
106106import qualified Data.Vector.Storable as VS
107107import qualified Data.Vector.Unboxed as VU
108108
109−#if !MIN_VERSION_base(4,8,0)
109+#if MIN_VERSION_base(4,8,0)
110+import Numeric.Natural
111+#else
110112import Control.Applicative ((<$>), (<*>), pure)
111113import Data.Foldable (Foldable)
112114import Data.Monoid (mempty)
@@ -348,6 +350,18 @@ instance FromJSON Integer where
348350 parseJSON = withScientific "Integral" $ pure . truncate
349351 {-# INLINE parseJSON #-}
350352
353+#if MIN_VERSION_base(4,8,0)
354+instance ToJSON Natural where
355+ toJSON = toJSON . toInteger
356+ {-# INLINE toJSON #-}
357+
358+ toEncoding = toEncoding . toInteger
359+ {-# INLINE toEncoding #-}
360+
361+instance FromJSON Natural where
362+ parseJSON = withScientific "Integral" $ pure . truncate
363+#endif
364+
351365instance ToJSON Int8 where
352366 toJSON = Number . fromIntegral
353367 {-# INLINE toJSON #-}