on master help sign in
Merge branch 'numeric-natural-instances' of https://github.com/mrkkrp/aeson
05249eaBas van Dijk
Data/Aeson/Types/Instances.hs+15−1
@@ -106,7 +106,9 @@ import qualified Data.Vector.Primitive as VP
106import qualified Data.Vector.Storable as VS
106import qualified Data.Vector.Storable as VS
107import qualified Data.Vector.Unboxed as VU
107import qualified Data.Vector.Unboxed as VU
108
108
109−#if !MIN_VERSION_base(4,8,0)
109+#if MIN_VERSION_base(4,8,0)
110+import Numeric.Natural
111+#else
110import Control.Applicative ((<$>), (<*>), pure)
112import Control.Applicative ((<$>), (<*>), pure)
111import Data.Foldable (Foldable)
113import Data.Foldable (Foldable)
112import Data.Monoid (mempty)
114import Data.Monoid (mempty)
@@ -348,6 +350,18 @@ instance FromJSON Integer where
348 parseJSON = withScientific "Integral" $ pure . truncate
350 parseJSON = withScientific "Integral" $ pure . truncate
349 {-# INLINE parseJSON #-}
351 {-# INLINE parseJSON #-}
350
352
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+
351instance ToJSON Int8 where
365instance ToJSON Int8 where
352 toJSON = Number . fromIntegral
366 toJSON = Number . fromIntegral
353 {-# INLINE toJSON #-}
367 {-# INLINE toJSON #-}