on master help sign in
Add ToJSON1 Proxy, and ToJSON2 Tagged
commita110629223ffbffd8f0b96bab70695a269228d64 authorOleg Grenrus <oleg.grenrus@iki.fi> dateSun 20 Nov 2016, 14:42 (10 years ago) parentadf9657
2 files changed+23−1
Data/Aeson/Types/FromJSON.hs+9 Data/Aeson/Types/ToJSON.hs+14−1
Data/Aeson/Types/FromJSON.hs+9
@@ -1725,12 +1725,21 @@ instance FromJSON a => FromJSON (Semigroup.Option a) where
17251725-- tagged
17261726-------------------------------------------------------------------------------
17271727
1728+instance FromJSON1 Proxy where
1729+ {-# INLINE liftParseJSON #-}
1730+ liftParseJSON _ _ Null = pure Proxy
1731+ liftParseJSON _ _ v = typeMismatch "Proxy" v
1732+
17281733instance FromJSON (Proxy a) where
17291734 {-# INLINE parseJSON #-}
17301735 parseJSON Null = pure Proxy
17311736 parseJSON v = typeMismatch "Proxy" v
17321737
17331738
1739+instance FromJSON2 Tagged where
1740+ liftParseJSON2 _ _ p _ = fmap Tagged . p
1741+ {-# INLINE liftParseJSON2 #-}
1742+
17341743instance FromJSON1 (Tagged a) where
17351744 liftParseJSON p _ = fmap Tagged . p
17361745 {-# INLINE liftParseJSON #-}
Data/Aeson/Types/ToJSON.hs+14−1
@@ -2165,6 +2165,13 @@ instance ToJSON a => ToJSON (Semigroup.Option a) where
21652165-- tagged
21662166-------------------------------------------------------------------------------
21672167
2168+instance ToJSON1 Proxy where
2169+ liftToJSON _ _ _ = Null
2170+ {-# INLINE liftToJSON #-}
2171+
2172+ liftToEncoding _ _ _ = E.null_
2173+ {-# INLINE liftToEncoding #-}
2174+
21682175instance ToJSON (Proxy a) where
21692176 toJSON _ = Null
21702177 {-# INLINE toJSON #-}
@@ -2173,6 +2180,13 @@ instance ToJSON (Proxy a) where
21732180 {-# INLINE toEncoding #-}
21742181
21752182
2183+instance ToJSON2 Tagged where
2184+ liftToJSON2 _ _ t _ (Tagged x) = t x
2185+ {-# INLINE liftToJSON2 #-}
2186+
2187+ liftToEncoding2 _ _ t _ (Tagged x) = t x
2188+ {-# INLINE liftToEncoding2 #-}
2189+
21762190instance ToJSON1 (Tagged a) where
21772191 liftToJSON t _ (Tagged x) = t x
21782192 {-# INLINE liftToJSON #-}
@@ -2187,7 +2201,6 @@ instance ToJSON b => ToJSON (Tagged a b) where
21872201 toEncoding = toEncoding1
21882202 {-# INLINE toEncoding #-}
21892203
2190−
21912204instance ToJSONKey b => ToJSONKey (Tagged a b) where
21922205 toJSONKey = contramapToJSONKeyFunction unTagged toJSONKey
21932206 toJSONKeyList = contramapToJSONKeyFunction (fmap unTagged) toJSONKeyList