on master help sign in
Merge pull request #482 from phadej/proxy-one

Add ToJSON1 Proxy, and ToJSON2 Tagged

commitc14903826cb46755f9ed127be62d0bff2844f6fe authorAdam Bergmark <adam@bergmark.nl> dateSun 11 Dec 2016, 12:54 (10 years ago) parent47a3a2ca110629
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
@@ -2174,6 +2174,13 @@ instance ToJSON a => ToJSON (Semigroup.Option a) where
21742174-- tagged
21752175-------------------------------------------------------------------------------
21762176
2177+instance ToJSON1 Proxy where
2178+ liftToJSON _ _ _ = Null
2179+ {-# INLINE liftToJSON #-}
2180+
2181+ liftToEncoding _ _ _ = E.null_
2182+ {-# INLINE liftToEncoding #-}
2183+
21772184instance ToJSON (Proxy a) where
21782185 toJSON _ = Null
21792186 {-# INLINE toJSON #-}
@@ -2182,6 +2189,13 @@ instance ToJSON (Proxy a) where
21822189 {-# INLINE toEncoding #-}
21832190
21842191
2192+instance ToJSON2 Tagged where
2193+ liftToJSON2 _ _ t _ (Tagged x) = t x
2194+ {-# INLINE liftToJSON2 #-}
2195+
2196+ liftToEncoding2 _ _ t _ (Tagged x) = t x
2197+ {-# INLINE liftToEncoding2 #-}
2198+
21852199instance ToJSON1 (Tagged a) where
21862200 liftToJSON t _ (Tagged x) = t x
21872201 {-# INLINE liftToJSON #-}
@@ -2196,7 +2210,6 @@ instance ToJSON b => ToJSON (Tagged a b) where
21962210 toEncoding = toEncoding1
21972211 {-# INLINE toEncoding #-}
21982212
2199−
22002213instance ToJSONKey b => ToJSONKey (Tagged a b) where
22012214 toJSONKey = contramapToJSONKeyFunction unTagged toJSONKey
22022215 toJSONKeyList = contramapToJSONKeyFunction (fmap unTagged) toJSONKeyList