@@ -61,6 +61,7 @@ module Data.Aeson.Types.Instances
6161 , typeMismatch
6262 ) where
6363
64+import Control.Applicative (Const(..))
6465import Data.Aeson.Encode.Functions (brackets, builder, encode, foldable, list)
6566import Data.Aeson.Functions (hashMapKey, mapHashKeyVal, mapKey, mapKeyVal)
6667import Data.Aeson.Types.Class
@@ -75,8 +76,10 @@ import Data.List.NonEmpty (NonEmpty(..))
7576import Data.Maybe (fromMaybe)
7677import Data.Monoid ((<>))
7778import Data.Monoid (Dual(..), First(..), Last(..))
79+import Data.Proxy (Proxy(..))
7880import Data.Ratio (Ratio, (%), numerator, denominator)
7981import Data.Scientific (Scientific)
82+import Data.Tagged (Tagged(..))
8083import Data.Text (Text, pack, unpack)
8184import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
8285 ZonedTime)
@@ -116,7 +119,6 @@ import qualified Data.Vector.Unboxed as VU
116119#else
117120import Control.Applicative ((<$>), (<*>), pure)
118121import Data.Monoid (mempty)
119−import Data.Traversable as Tr (traverse)
120122import Data.Word (Word)
121123#endif
122124
@@ -1543,6 +1545,40 @@ instance FromJSON Version where
15431545 go (_ : xs) = go xs
15441546 go _ = fail $ "could not parse Version"
15451547
1548+instance ToJSON (Proxy a) where
1549+ toJSON _ = Null
1550+ {-# INLINE toJSON #-}
1551+
1552+ toEncoding _ = Encoding E.null_
1553+ {-# INLINE toEncoding #-}
1554+
1555+instance FromJSON (Proxy a) where
1556+ {-# INLINE parseJSON #-}
1557+ parseJSON Null = pure Proxy
1558+ parseJSON v = typeMismatch "Proxy" v
1559+
1560+instance ToJSON b => ToJSON (Tagged a b) where
1561+ toJSON (Tagged x) = toJSON x
1562+ {-# INLINE toJSON #-}
1563+
1564+ toEncoding (Tagged x) = toEncoding x
1565+ {-# INLINE toEncoding #-}
1566+
1567+instance FromJSON b => FromJSON (Tagged a b) where
1568+ {-# INLINE parseJSON #-}
1569+ parseJSON = fmap Tagged . parseJSON
1570+
1571+instance ToJSON a => ToJSON (Const a b) where
1572+ toJSON (Const x) = toJSON x
1573+ {-# INLINE toJSON #-}
1574+
1575+ toEncoding (Const x) = toEncoding x
1576+ {-# INLINE toEncoding #-}
1577+
1578+instance FromJSON a => FromJSON (Const a b) where
1579+ {-# INLINE parseJSON #-}
1580+ parseJSON = fmap Const . parseJSON
1581+
15461582-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
15471583-- and fails using @'typeMismatch' expected@ otherwise.
15481584withObject :: String -> (Object -> Parser a) -> Value -> Parser a