Skip to content

Add allNullaryConstructorTagModifier option #1143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wi11dey
Copy link

@wi11dey wi11dey commented Jul 31, 2025

Often, enums (all nullary contructors) are encoded differently than sum types.

For example, if I have

data State = Launching | Launched | Terminated | MarkedForDeletion

I might want to have these states encoded as LAUNCHING, LAUNCHED, TERMINATED, MARKED_FOR_DELETION, respectively.

However, using the existing constructorTagModifier is not satisfactory for this because I don't necessarily want my sum types, e.g.

data Employee = Manager { subordinates :: [Employee] } | Junior

to be encoded the same way as an enum.

I've added an optional field allNullaryConstructorTagModifier (it's Maybe so that there's no behavior change to any existing usages of Aeson, in case someone is depending on constructorTagModifier also applying to all-nullary datatypes). When it's Nothing, everything is the same as today. When it's non-Nothing it's used instead of constructorTagModifier for all-nullary datatypes, for the purposes of handling enums differently than sum types.

Please let me know if you'd like any changes to the api

@wi11dey wi11dey force-pushed the wdey/allNullaryConstructorTagModifier branch from 5834a26 to 1175bcc Compare July 31, 2025 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant