Skip to content

Commit c1f6c14

Browse files
committed
handle omitted field propagation for comp1
1 parent 0f36b77 commit c1f6c14

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/Data/Aeson/Types/FromJSON.hs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1028,16 +1028,13 @@ instance (FromJSON1 f) => GFromJSON One (Rec1 f) where
10281028
gParseJSON _opts (From1Args o pj pjl) = fmap Rec1 . liftParseJSON o pj pjl
10291029
{-# INLINE gParseJSON #-}
10301030

1031-
instance (FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) where
1031+
instance (FromJSON1 f, GFromJSON One g, GOmitFromJSON One g) => GFromJSON One (f :.: g) where
10321032
-- If an occurrence of the last type parameter is nested inside two
10331033
-- composed types, it is decoded by using the outermost type's FromJSON1
10341034
-- instance to generically decode the innermost type:
1035-
--
1036-
-- Note: the ommitedField is not passed here.
1037-
-- This might be related for :.: associated the wrong way in Generics Rep.
10381035
gParseJSON opts fargs =
10391036
let gpj = gParseJSON opts fargs
1040-
in fmap Comp1 . liftParseJSON Nothing gpj (listParser gpj)
1037+
in fmap Comp1 . liftParseJSON (gOmittedField fargs) gpj (listParser gpj)
10411038
{-# INLINE gParseJSON #-}
10421039

10431040
instance FromJSON a => GOmitFromJSON arity (K1 i a) where

src/Data/Aeson/Types/ToJSON.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -884,14 +884,15 @@ instance ( WriteProduct arity a, WriteProduct arity b
884884

885885
instance ( ToJSON1 f
886886
, GToJSON' Value One g
887+
, GOmitToJSON Value One g
887888
) => GToJSON' Value One (f :.: g)
888889
where
889890
-- If an occurrence of the last type parameter is nested inside two
890891
-- composed types, it is encoded by using the outermost type's ToJSON1
891892
-- instance to generically encode the innermost type:
892893
gToJSON opts targs =
893894
let gtj = gToJSON opts targs in
894-
liftToJSON (const False) gtj (listValue gtj) . unComp1
895+
liftToJSON (gOmitField targs) gtj (listValue gtj) . unComp1
895896
{-# INLINE gToJSON #-}
896897

897898
--------------------------------------------------------------------------------
@@ -931,14 +932,15 @@ instance ( EncodeProduct arity a
931932

932933
instance ( ToJSON1 f
933934
, GToJSON' Encoding One g
935+
, GOmitToJSON Encoding One g
934936
) => GToJSON' Encoding One (f :.: g)
935937
where
936938
-- If an occurrence of the last type parameter is nested inside two
937939
-- composed types, it is encoded by using the outermost type's ToJSON1
938940
-- instance to generically encode the innermost type:
939941
gToJSON opts targs =
940942
let gte = gToJSON opts targs in
941-
liftToEncoding (const False) gte (listEncoding gte) . unComp1
943+
liftToEncoding (gOmitField targs) gte (listEncoding gte) . unComp1
942944
{-# INLINE gToJSON #-}
943945

944946
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)