@@ -61,6 +61,7 @@ module Data.Aeson.Types.Instances
61 , typeMismatch
61 , typeMismatch
64+import Control.Applicative (Const(..))
64import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, list)
65import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, list)
65import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
66import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
66import Data.Aeson.Types.Class
67import Data.Aeson.Types.Class
@@ -74,8 +75,10 @@ import Data.Int (Int8, Int16, Int32, Int64)
74import Data.Maybe (fromMaybe)
75import Data.Maybe (fromMaybe)
75import Data.Monoid ((<>))
76import Data.Monoid ((<>))
76import Data.Monoid (Dual(..), First(..), Last(..))
77import Data.Monoid (Dual(..), First(..), Last(..))
78+import Data.Proxy (Proxy(..))
77import Data.Ratio (Ratio, (%), numerator, denominator)
79import Data.Ratio (Ratio, (%), numerator, denominator)
78import Data.Scientific (Scientific)
80import Data.Scientific (Scientific)
81+import Data.Tagged (Tagged(..))
79import Data.Text (Text, pack, unpack)
82import Data.Text (Text, pack, unpack)
80import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
83import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
81 ZonedTime)
84 ZonedTime)
@@ -115,7 +118,6 @@ import Numeric.Natural
116import Control.Applicative ((<$>), (<*>), pure)
119import Control.Applicative ((<$>), (<*>), pure)
117import Data.Monoid (mempty)
120import Data.Monoid (mempty)
118−import Data.Traversable as Tr (traverse)
119import Data.Word (Word)
121import Data.Word (Word)
@@ -1530,6 +1532,40 @@ instance FromJSON Version where
1530 go (_ : xs) = go xs
1532 go (_ : xs) = go xs
1531 go _ = fail $ "could not parse Version"
1533 go _ = fail $ "could not parse Version"
1535+instance ToJSON (Proxy a) where
1537+ {-# INLINE toJSON #-}
1539+ toEncoding _ = Encoding E.null_
1540+ {-# INLINE toEncoding #-}
1542+instance FromJSON (Proxy a) where
1543+ {-# INLINE parseJSON #-}
1544+ parseJSON Null = pure Proxy
1545+ parseJSON v = typeMismatch "Proxy" v
1547+instance ToJSON b => ToJSON (Tagged a b) where
1548+ toJSON (Tagged x) = toJSON x
1549+ {-# INLINE toJSON #-}
1551+ toEncoding (Tagged x) = toEncoding x
1552+ {-# INLINE toEncoding #-}
1554+instance FromJSON b => FromJSON (Tagged a b) where
1555+ {-# INLINE parseJSON #-}
1556+ parseJSON = fmap Tagged . parseJSON
1558+instance ToJSON a => ToJSON (Const a b) where
1559+ toJSON (Const x) = toJSON x
1560+ {-# INLINE toJSON #-}
1562+ toEncoding (Const x) = toEncoding x
1563+ {-# INLINE toEncoding #-}
1565+instance FromJSON a => FromJSON (Const a b) where
1566+ {-# INLINE parseJSON #-}
1567+ parseJSON = fmap Const . parseJSON
1533-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
1569-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
1534-- and fails using @'typeMismatch' expected@ otherwise.
1570-- and fails using @'typeMismatch' expected@ otherwise.
1535withObject :: String -> (Object -> Parser a) -> Value -> Parser a
1571withObject :: String -> (Object -> Parser a) -> Value -> Parser a