@@ -32,6 +32,7 @@ import qualified Control.Monad.State as S
3232import Data.Aeson
3333import Data.Aeson.Types (Parser)
3434import Data.Constraint
35+import Data.List (intercalate)
3536import Data.Maybe (catMaybes)
3637import Data.Proxy
3738import qualified Data.Text as T
@@ -42,11 +43,17 @@ import GHC.OverloadedLabels
4243import GHC.Prim
4344import GHC.ST (ST (..), runST)
4445import GHC.TypeLits
45−import Generic.Data (gshowsPrec)
46−import Generic.Data.Internal.Show (GShow)
4746import qualified Optics.Lens as OL
4847import Unsafe.Coerce
4948import Prelude
49+#if MIN_VERSION_aeson(2,0,0)
50+import Data.Aeson.Key (fromText, fromString)
51+#else
52+fromText :: a -> a
53+fromText = id
54+fromString :: String -> T.Text
55+fromString = T.pack
56+#endif
5057
5158-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
5259-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -102,13 +109,12 @@ defaultJSONOptions = JSONOptions {fieldTransform = id}
102109type role Rec representational
103110
104111instance
105− ( RecApply lts lts Show,
106− GShow Proxy (Rep (Rec lts)),
107− Generic (Rec lts)
112+ ( RecApply lts lts Show
108113 ) =>
109114 Show (Rec lts)
110115 where
111− show = (\x -> if null x then "{}" else x) . unwords . drop 1 . words . flip (gshowsPrec 0) ""
116+ show rec = "{" ++ formatted ++ "}"
117+ where formatted = intercalate ", " $ map (\(k, v) -> k ++ " = " ++ v) $ showRec rec
112118
113119instance RecEq lts lts => Eq (Rec lts) where
114120 (==) (a :: Rec lts) (b :: Rec lts) = recEq a b (Proxy :: Proxy lts)
@@ -560,16 +566,16 @@ class ToJSON a => EncodeField a where
560566
561567instance ToJSON a => EncodeField a where
562568 encodeField = pure . toJSON
563− encodeKV = (.=)
569+ encodeKV k v = fromText k .= v
564570
565571instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
566572 encodeField = fmap toJSON
567573 encodeKV _ Nothing = mempty
568− encodeKV k v = k .= v
574+ encodeKV k v = fromText k .= v
569575
570576recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
571577recToValue options r =
572− object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (T.pack (fieldTransform options k),) <$> encodeField v) r
578+ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (fromString (fieldTransform options k),) <$> encodeField v) r
573579
574580recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
575581recToEncoding options r =
@@ -674,10 +680,10 @@ class FromJSON a => ParseField a where
674680 parseField :: Object -> T.Text -> Parser a
675681
676682instance FromJSON a => ParseField a where
677− parseField = (.:)
683+ parseField o k = o .: fromText k
678684
679685instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
680− parseField = (.:?)
686+ parseField o k = o .:? fromText k
681687
682688instance
683689 ( KnownSymbol l,