@@ -46,7 +46,14 @@ import GHC.TypeLits
46import qualified Optics.Lens as OL
46import qualified Optics.Lens as OL
47import Unsafe.Coerce
47import Unsafe.Coerce
48import Prelude
48import Prelude
49+#if MIN_VERSION_aeson(2,0,0)
49โimport qualified Data.Aeson.Key as Key
50+import Data.Aeson.Key (fromText, fromString)
54+fromString :: String -> T.Text
51-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
58-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
52-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
59-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -559,16 +566,16 @@ class ToJSON a => EncodeField a where
560instance ToJSON a => EncodeField a where
567instance ToJSON a => EncodeField a where
561 encodeField = pure . toJSON
568 encodeField = pure . toJSON
562โ encodeKV k v = Key.fromText k .= v
569+ encodeKV k v = fromText k .= v
564instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
571instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
565 encodeField = fmap toJSON
572 encodeField = fmap toJSON
566 encodeKV _ Nothing = mempty
573 encodeKV _ Nothing = mempty
567โ encodeKV k v = Key.fromText k .= v
574+ encodeKV k v = fromText k .= v
569recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
576recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
570recToValue options r =
577recToValue options r =
571โ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (Key.fromString (fieldTransform options k),) <$> encodeField v) r
578+ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (fromString (fieldTransform options k),) <$> encodeField v) r
573recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
580recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
574recToEncoding options r =
581recToEncoding options r =
@@ -673,10 +680,10 @@ class FromJSON a => ParseField a where
673 parseField :: Object -> T.Text -> Parser a
680 parseField :: Object -> T.Text -> Parser a
675instance FromJSON a => ParseField a where
682instance FromJSON a => ParseField a where
676โ parseField o k = o .: Key.fromText k
683+ parseField o k = o .: fromText k
678instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
685instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
679โ parseField o k = o .:? Key.fromText k
686+ parseField o k = o .:? fromText k
682 ( KnownSymbol l,
689 ( KnownSymbol l,