Skip to content

Add option tagAsContentsFieldName to TaggedObject SumEncoding #1142

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

Hello,

Thanks for making aeson.

I've added a flag tagAsContentsFieldName which will allow encoding sum types as

{
  "tag": "constructorName"
  "constructorName": { ... contents ... }
}

This style is used in type encoding standards such as https://palantir.github.io/conjure/#/docs/spec/wire?id=_54-union-json-format.

Initially I was thinking to make contentsFieldName be a String -> String and provide it the constructor name, which would be flexible enough to allow the default behavior of const "contents" and also be able to dynamically use the constructor name (and even modify it), but this would break backcompat and also not be serializable to the TH implementation.

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

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