From be593c72d98e658e42f8003a24d0b3f8c77ad433 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Tue, 20 Aug 2019 14:20:12 +0200 Subject: [PATCH] Handle FromJSONKey instances properly --- src/Hanafuda/Message.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Hanafuda/Message.hs b/src/Hanafuda/Message.hs index fbf5ad7..8b6afad 100644 --- a/src/Hanafuda/Message.hs +++ b/src/Hanafuda/Message.hs @@ -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