OXY-147: add JsonEncoder.Omit typeclass and @jsonOmit annotation - #297
Open
Kalin-Rudnicki wants to merge 1 commit into
Open
OXY-147: add JsonEncoder.Omit typeclass and @jsonOmit annotation#297Kalin-Rudnicki wants to merge 1 commit into
Kalin-Rudnicki wants to merge 1 commit into
Conversation
Mirror the jsonSecret/SecretValue/JsonEncoder.Secret pattern for unconditional field suppression (never on the wire) rather than redaction. - annotations: add @jsonOmit - JsonEncoder: add `def omit`, Omit/OmitEncoder (addToObject = false); handle @jsonOmit in productDeriver - OmitValue: new opaque wrapper with encoder + decoder givens - DeriveProductJsonEncoder: emit Growable.empty for @jsonOmit (wins over flatten) - DeriveProductJsonDecoder: drop omitted key from `keys`; reconstruct from onMissingFromObject/default (present key ignored) - JsonSchema: hide @jsonOmit fields from the emitted schema - predef/json: export jsonOmit + OmitValue - tests: JsonSpec omit suite + schema emitter omit test Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a first-class "omit from JSON" capability to
oxygen-json, mirroring the existingjsonSecret/SecretValue/JsonEncoder.Secretpattern but for unconditional suppression (a field that never appears on the wire) rather than redaction.Two mechanisms:
@jsonOmitannotation — omit a plain field without changing its type.OmitValue[A]opaque wrapper — the type carries omit semantics.Changes
annotations.scala:@jsonOmit.JsonEncoder.scala:def omit+Omit/OmitEncoder(addToObject = false); handle@jsonOmitinproductDeriver.OmitValue.scala: new opaque wrapper with encoder + decoder givens.DeriveProductJsonEncoder.scala: emitGrowable.emptyfor@jsonOmitfields in both object-field paths (wins over@jsonFlatten).DeriveProductJsonDecoder.scala: omitted key dropped fromkeys; field reconstructed fromonMissingFromObject/default.JsonSchema.scala: hide@jsonOmitfields from the emitted schema.predef/json.scala: exportjsonOmit+OmitValue.JsonSpecomit suite +JsonSchemaEmitterSpecomit-hidden test.Key decision (needs a look)
Decode-when-key-is-present differs by mechanism:
@jsonOmit: fully transient — incoming value ignored (rejected as extra under@jsonStrict).OmitValue[A]: encode-only — a present key is decoded normally (no annotation for the decoder macro to hook).Omitted plain fields need a constructor default (or an
onMissing-providing type likeOption) to decode.Verification
oxygen-jsonJVM/compile,oxygen-schemaJVM/compile,utJVM/testOnly oxygen.json.JsonSpec(85 passed) andoxygen.schema.*all green.Full write-up incl. assumptions + confidence score:
report/OXY-147.md.🤖 Generated with Claude Code