Handle FromJSONKey instances properly

This commit is contained in:
Tissevert 2019-08-20 14:20:12 +02:00
parent 3e0f1834d1
commit be593c72d9
1 changed files with 5 additions and 4 deletions

View File

@ -13,7 +13,7 @@ module Hanafuda.Message (
import Data.Char (toLower)
import Data.Aeson (
FromJSON(..), FromJSONKey(..), Options(..), SumEncoding(..), ToJSON(..), ToJSONKey(..)
FromJSON(..), FromJSONKey(..), FromJSONKeyFunction(..), Options(..), SumEncoding(..), ToJSON(..), ToJSONKey(..)
, Value, (.:), (.=), defaultOptions, eitherDecode', encode, genericParseJSON
, genericToEncoding, object, pairs, withObject
)
@ -21,7 +21,7 @@ import Data.Aeson.Types (toJSONKeyText)
import Data.Map (Map)
import Data.Monoid ((<>))
import Data.Text (Text)
import qualified Data.Text as Text (pack)
import qualified Data.Text as Text (pack, unpack)
import GHC.Generics (Generic)
import qualified Hanafuda (Card(..), Flower(..), Pack, cardsOfPack, empty, packOfCards)
import Hanafuda.Key (Key(..), getKey)
@ -34,7 +34,7 @@ import Hanafuda.Player (Player(..), Players(..))
deriving instance Generic PlayerKey
instance FromJSON PlayerKey
instance FromJSONKey PlayerKey where
fromJSONKey = fromJSONKey
fromJSONKey = FromJSONKeyText (Key . read . Text.unpack)
instance ToJSON PlayerKey where
toEncoding = genericToEncoding defaultOptions
instance ToJSONKey PlayerKey where
@ -101,7 +101,8 @@ instance ToJSON KoiKoi.Action where
deriving instance Generic KoiKoi.Yaku
instance FromJSON KoiKoi.Yaku
instance FromJSONKey KoiKoi.Yaku
instance FromJSONKey KoiKoi.Yaku where
fromJSONKey = FromJSONKeyText (read . Text.unpack)
instance ToJSON KoiKoi.Yaku where
toEncoding = genericToEncoding defaultOptions
instance ToJSONKey KoiKoi.Yaku where