Skip to content

Commit c5f586e

Browse files
authored
Add To/FromJSONKey instances for Const (#798)
* To/FromJSONKey for Const
1 parent 03f9655 commit c5f586e

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Data/Aeson/Types/FromJSON.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,9 @@ instance FromJSON a => FromJSON (Const a b) where
14591459
{-# INLINE parseJSON #-}
14601460
parseJSON = fmap Const . parseJSON
14611461

1462+
instance (FromJSON a, FromJSONKey a) => FromJSONKey (Const a b) where
1463+
fromJSONKey = fmap Const fromJSONKey
1464+
14621465

14631466
instance FromJSON1 Maybe where
14641467
liftParseJSON _ _ Null = pure Nothing

Data/Aeson/Types/ToJSON.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,9 @@ instance ToJSON a => ToJSON (Const a b) where
12341234
toEncoding (Const x) = toEncoding x
12351235
{-# INLINE toEncoding #-}
12361236

1237+
instance (ToJSON a, ToJSONKey a) => ToJSONKey (Const a b) where
1238+
toJSONKey = contramap getConst toJSONKey
1239+
12371240

12381241
instance ToJSON1 Maybe where
12391242
liftToJSON t _ (Just a) = t a

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
For the latest version of this document, please see [https://github.com/bos/aeson/blob/master/changelog.md](https://github.com/bos/aeson/blob/master/changelog.md).
22

3+
### Upcoming
4+
5+
* Add instances for `ToJSONKey` and `FromJSONKey` to `Const`.
6+
37
### 1.5.3.0
48

59
* Add instances for types in `strict` and `data-fix` packages, thanks to Oleg Grenrus.

0 commit comments

Comments
 (0)