@@ -56,6 +56,7 @@ module Data.Aeson.Types.Internal
5656 fieldLabelModifier
5757 , constructorTagModifier
5858 , allNullaryToStringTag
59+ , allNullaryConstructorTagModifier
5960 , omitNothingFields
6061 , allowOmittedFields
6162 , sumEncoding
@@ -714,6 +715,10 @@ data Options = Options
714715 -- nullary constructors, will be encoded to just a string with
715716 -- the constructor tag. If 'False' the encoding will always
716717 -- follow the `sumEncoding`.
718+ , allNullaryConstructorTagModifier :: Maybe (String -> String )
719+ -- ^ If not 'Nothing', specifies the function to be used instead of
720+ -- 'constructorTagModifier' whenever 'allNullaryToStringTag'
721+ -- is in effect. Useful for encoding enums specially.
717722 , omitNothingFields :: Bool
718723 -- ^ If 'True', record fields with a 'Nothing' value will be
719724 -- omitted from the resulting object. If 'False', the resulting
@@ -744,12 +749,13 @@ data Options = Options
744749 }
745750
746751instance Show Options where
747- show (Options f c a o q s u t r) =
752+ show (Options f c a ac o q s u t r) =
748753 " Options {"
749754 ++ intercalate " , "
750755 [ " fieldLabelModifier =~ " ++ show (f " exampleField" )
751756 , " constructorTagModifier =~ " ++ show (c " ExampleConstructor" )
752757 , " allNullaryToStringTag = " ++ show a
758+ , " allNullaryConstructorTagModifier =~ " ++ show (($ " ExampleConstructor" ) <$> ac)
753759 , " omitNothingFields = " ++ show o
754760 , " allowOmittedFields = " ++ show q
755761 , " sumEncoding = " ++ show s
@@ -843,15 +849,16 @@ data JSONKeyOptions = JSONKeyOptions
843849-- @
844850defaultOptions :: Options
845851defaultOptions = Options
846- { fieldLabelModifier = id
847- , constructorTagModifier = id
848- , allNullaryToStringTag = True
849- , omitNothingFields = False
850- , allowOmittedFields = True
851- , sumEncoding = defaultTaggedObject
852- , unwrapUnaryRecords = False
853- , tagSingleConstructors = False
854- , rejectUnknownFields = False
852+ { fieldLabelModifier = id
853+ , constructorTagModifier = id
854+ , allNullaryToStringTag = True
855+ , allNullaryConstructorTagModifier = Nothing
856+ , omitNothingFields = False
857+ , allowOmittedFields = True
858+ , sumEncoding = defaultTaggedObject
859+ , unwrapUnaryRecords = False
860+ , tagSingleConstructors = False
861+ , rejectUnknownFields = False
855862 }
856863
857864-- | Default 'TaggedObject' 'SumEncoding' options:
0 commit comments