on master help sign in
Update to work with 20.9 snapshot
commit96febf9bab020c4f2acfdc2e45dfc88668bdd71f authoriko <mail@iko.soy> dateWed 1 Feb 2023, 10:52 (4 years ago) parent0bfb2fa
2 files changed+7−6
jrec.cabal+1−1 src/JRec/Internal.hs+6−5
jrec.cabal+1−1
@@ -37,7 +37,7 @@ common library-common
3737 default-language: Haskell2010
3838 build-depends:
3939 aeson
40− , base >=4.13 && <4.15
40+ , base >=4.13 && <4.17
4141 , constraints
4242 , deepseq
4343 , generic-data
src/JRec/Internal.hs+6−5
@@ -46,6 +46,7 @@ import GHC.TypeLits
4646import qualified Optics.Lens as OL
4747import Unsafe.Coerce
4848import Prelude
49+import qualified Data.Aeson.Key as Key
4950
5051-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
5152-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -558,16 +559,16 @@ class ToJSON a => EncodeField a where
558559
559560instance ToJSON a => EncodeField a where
560561 encodeField = pure . toJSON
561− encodeKV = (.=)
562+ encodeKV k v = Key.fromText k .= v
562563
563564instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
564565 encodeField = fmap toJSON
565566 encodeKV _ Nothing = mempty
566− encodeKV k v = k .= v
567+ encodeKV k v = Key.fromText k .= v
567568
568569recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
569570recToValue options r =
570− object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (T.pack (fieldTransform options k),) <$> encodeField v) r
571+ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (Key.fromString (fieldTransform options k),) <$> encodeField v) r
571572
572573recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
573574recToEncoding options r =
@@ -672,10 +673,10 @@ class FromJSON a => ParseField a where
672673 parseField :: Object -> T.Text -> Parser a
673674
674675instance FromJSON a => ParseField a where
675− parseField = (.:)
676+ parseField o k = o .: Key.fromText k
676677
677678instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
678− parseField = (.:?)
679+ parseField o k = o .:? Key.fromText k
679680
680681instance
681682 ( KnownSymbol l,