@@ -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
@@ -74,8 +75,10 @@ import Data.Int (Int8, Int16, Int32, Int64)
7475import Data.Maybe (fromMaybe)
7576import Data.Monoid ((<>))
7677import Data.Monoid (Dual(..), First(..), Last(..))
78+import Data.Proxy (Proxy(..))
7779import Data.Ratio (Ratio, (%), numerator, denominator)
7880import Data.Scientific (Scientific)
81+import Data.Tagged (Tagged(..))
7982import Data.Text (Text, pack, unpack)
8083import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
8184 ZonedTime)
@@ -115,7 +118,6 @@ import Numeric.Natural
115118#else
116119import Control.Applicative ((<$>), (<*>), pure)
117120import Data.Monoid (mempty)
118−import Data.Traversable as Tr (traverse)
119121import Data.Word (Word)
120122#endif
121123
@@ -1530,6 +1532,40 @@ instance FromJSON Version where
15301532 go (_ : xs) = go xs
15311533 go _ = fail $ "could not parse Version"
15321534
1535+instance ToJSON (Proxy a) where
1536+ toJSON _ = Null
1537+ {-# INLINE toJSON #-}
1538+
1539+ toEncoding _ = Encoding E.null_
1540+ {-# INLINE toEncoding #-}
1541+
1542+instance FromJSON (Proxy a) where
1543+ {-# INLINE parseJSON #-}
1544+ parseJSON Null = pure Proxy
1545+ parseJSON v = typeMismatch "Proxy" v
1546+
1547+instance ToJSON b => ToJSON (Tagged a b) where
1548+ toJSON (Tagged x) = toJSON x
1549+ {-# INLINE toJSON #-}
1550+
1551+ toEncoding (Tagged x) = toEncoding x
1552+ {-# INLINE toEncoding #-}
1553+
1554+instance FromJSON b => FromJSON (Tagged a b) where
1555+ {-# INLINE parseJSON #-}
1556+ parseJSON = fmap Tagged . parseJSON
1557+
1558+instance ToJSON a => ToJSON (Const a b) where
1559+ toJSON (Const x) = toJSON x
1560+ {-# INLINE toJSON #-}
1561+
1562+ toEncoding (Const x) = toEncoding x
1563+ {-# INLINE toEncoding #-}
1564+
1565+instance FromJSON a => FromJSON (Const a b) where
1566+ {-# INLINE parseJSON #-}
1567+ parseJSON = fmap Const . parseJSON
1568+
15331569-- | @withObject expected f value@ applies @f@ to the 'Object' when @value@ is an @Object@
15341570-- and fails using @'typeMismatch' expected@ otherwise.
15351571withObject :: String -> (Object -> Parser a) -> Value -> Parser a