@@ -1,5 +1,5 @@
1{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving, Rank2Types,
1{-# LANGUAGE CPP, DeriveDataTypeable, GeneralizedNewtypeDeriving, Rank2Types,
2− RecordWildCards #-}
2+ RecordWildCards, TemplateHaskell #-}
5-- Module: Data.Aeson.Types.Internal
5-- Module: Data.Aeson.Types.Internal
@@ -53,6 +53,7 @@ module Data.Aeson.Types.Internal
53 , DotNetTime(..)
53 , DotNetTime(..)
56+import Control.Arrow (first)
56import Control.Applicative
57import Control.Applicative
57import Control.DeepSeq (NFData(..))
58import Control.DeepSeq (NFData(..))
58import Control.Monad (MonadPlus(..), ap)
59import Control.Monad (MonadPlus(..), ap)
@@ -71,7 +72,9 @@ import Data.Time.Format (FormatTime)
71import Data.Typeable (Typeable)
72import Data.Typeable (Typeable)
72import Data.Vector (Vector)
73import Data.Vector (Vector)
73import qualified Data.HashMap.Strict as H
74import qualified Data.HashMap.Strict as H
75+import qualified Data.Scientific as S
74import qualified Data.Vector as V
76import qualified Data.Vector as V
77+import qualified Language.Haskell.TH.Syntax as TH
76#if !MIN_VERSION_base(4,8,0)
79#if !MIN_VERSION_base(4,8,0)
77import Data.Foldable (Foldable(..))
80import Data.Foldable (Foldable(..))
@@ -392,6 +395,21 @@ hashValue s Null = s `hashWithSalt` (5::Int)
392instance Hashable Value where
395instance Hashable Value where
393 hashWithSalt = hashValue
396 hashWithSalt = hashValue
399+instance TH.Lift Value where
400+ lift Null = [| Null |]
401+ lift (Bool b) = [| Bool b |]
402+ lift (Number n) = [| Number (S.scientific c e) |]
405+ e = S.base10Exponent n
406+ lift (String t) = [| String (pack s) |]
408+ lift (Array a) = [| Array (V.fromList a') |]
409+ where a' = V.toList a
410+ lift (Object o) = [| Object (H.fromList . map (first pack) $ o') |]
411+ where o' = map (first unpack) . H.toList $ o
395-- | The empty array.
413-- | The empty array.
396emptyArray :: Value
414emptyArray :: Value
397emptyArray = Array V.empty
415emptyArray = Array V.empty