@@ -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
@@ -75,8 +76,10 @@ import Data.List.NonEmpty (NonEmpty(..))
75import Data.Maybe (fromMaybe)
76import Data.Maybe (fromMaybe)
76import Data.Monoid ((<>))
77import Data.Monoid ((<>))
77import Data.Monoid (Dual(..), First(..), Last(..))
78import Data.Monoid (Dual(..), First(..), Last(..))
79+import Data.Proxy (Proxy(..))
78import Data.Ratio (Ratio, (%), numerator, denominator)
80import Data.Ratio (Ratio, (%), numerator, denominator)
79import Data.Scientific (Scientific)
81import Data.Scientific (Scientific)
82+import Data.Tagged (Tagged(..))
80import Data.Text (Text, pack, unpack)
83import Data.Text (Text, pack, unpack)
81import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
84import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
82 ZonedTime)
85 ZonedTime)
@@ -116,7 +119,6 @@ import qualified Data.Vector.Unboxed as VU
117import Control.Applicative ((<$>), (<*>), pure)
120import Control.Applicative ((<$>), (<*>), pure)
118import Data.Monoid (mempty)
121import Data.Monoid (mempty)
119−import Data.Traversable as Tr (traverse)
120import Data.Word (Word)
122import Data.Word (Word)
@@ -1543,6 +1545,40 @@ instance FromJSON Version where
1543 go (_ : xs) = go xs
1545 go (_ : xs) = go xs
1544 go _ = fail $ "could not parse Version"
1546 go _ = fail $ "could not parse Version"
1548+instance ToJSON (Proxy a) where
1550+ {-# INLINE toJSON #-}
1552+ toEncoding _ = Encoding E.null_
1553+ {-# INLINE toEncoding #-}
1555+instance FromJSON (Proxy a) where
1556+ {-# INLINE parseJSON #-}
1557+ parseJSON Null = pure Proxy
1558+ parseJSON v = typeMismatch "Proxy" v
1560+instance ToJSON b => ToJSON (Tagged a b) where
1561+ toJSON (Tagged x) = toJSON x
1562+ {-# INLINE toJSON #-}
1564+ toEncoding (Tagged x) = toEncoding x
1565+ {-# INLINE toEncoding #-}
1567+instance FromJSON b => FromJSON (Tagged a b) where
1568+ {-# INLINE parseJSON #-}
1569+ parseJSON = fmap Tagged . parseJSON
1571+instance ToJSON a => ToJSON (Const a b) where
1572+ toJSON (Const x) = toJSON x
1573+ {-# INLINE toJSON #-}
1575+ toEncoding (Const x) = toEncoding x
1576+ {-# INLINE toEncoding #-}
1578+instance FromJSON a => FromJSON (Const a b) where
1579+ {-# INLINE parseJSON #-}
1580+ parseJSON = fmap Const . parseJSON
1546-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
1582-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
1547-- and fails using @'typeMismatch' expected@ otherwise.
1583-- and fails using @'typeMismatch' expected@ otherwise.
1548withObject :: String -> (Object -> Parser a) -> Value -> Parser a
1584withObject :: String -> (Object -> Parser a) -> Value -> Parser a