Skip to content

Support aeson-2.0.0.0 #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.2

- Support `aeson-2.0.0.0`

## 1.0.1

- Add instances for `time-1.11` types: `Month`, `Quarter`, `QuarterOfYear`
Expand Down
4 changes: 2 additions & 2 deletions binary-instances.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: binary-instances
version: 1.0.1
version: 1.0.2
synopsis: Orphan instances for binary
description:
`binary-instances` defines orphan instances for types in some popular packages.
Expand Down Expand Up @@ -35,7 +35,7 @@ library
default-language: Haskell2010
hs-source-dirs: src
build-depends:
aeson >=0.7.0.6 && <1.6
aeson >=0.7.0.6 && <1.6 || >=2.0.0.0 && <2.1
, base >=4.6.0.1 && <4.16
, binary >=0.5.1.1 && <0.8.9
, binary-orphans >=1.0.1 && <1.1
Expand Down
16 changes: 16 additions & 0 deletions src/Data/Binary/Instances/Aeson.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Binary.Instances.Aeson where

Expand All @@ -11,6 +12,11 @@ import Data.Binary.Instances.Vector ()

import qualified Data.Aeson as A

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as Key
import qualified Data.Aeson.KeyMap as KM
#endif

instance Binary A.Value where
get = do
t <- get :: Get Int
Expand All @@ -29,3 +35,13 @@ instance Binary A.Value where
put (A.Number v) = put (3 :: Int) >> put v
put (A.Bool v) = put (4 :: Int) >> put v
put A.Null = put (5 :: Int)

#if MIN_VERSION_aeson(2,0,0)
instance Binary Key.Key where
get = Key.fromText <$> get
put = put . Key.toText

instance Binary v => Binary (KM.KeyMap v) where
get = fmap KM.fromList get
put = put . KM.toList
#endif