Repository navigation
Set preferFlat = false for circe and spray-json Scala 2 macros - #534
Merged
Merged
Conversation
luksow
force-pushed
the
fix/prefer-flat-default
branch
from
March 28, 2026 23:14
47b6aca to
d42aaab
Compare
In kebs 2.x, flattening 1-element case classes was made optional via
CaseClass1ToValueClass. However, the Scala 2 macros for circe and
spray-json had preferFlat hardcoded to true, which caused the macro to
always abort for 1-element case classes and effectively required
CaseClass1ToValueClass to be mixed in.
Replace the static preferFlat flag with a dynamic check: the macro now
detects whether ValueClassLike is available (i.e., CaseClass1ToValueClass
is mixed in) and only aborts in that case. This aligns Scala 2 behavior
with Scala 3 which has no preferFlat mechanism at all.
Without CaseClass1ToValueClass: case class C(i: Int) → {"i": 1}
With CaseClass1ToValueClass: case class C(i: Int) → 1
luksow
force-pushed
the
fix/prefer-flat-default
branch
from
March 28, 2026 23:22
d42aaab to
c2ea0a9
Compare
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.
Summary
preferFlat = falseinKebsCirceMacrosandKebsSprayMacros(Scala 2) so that 1-element case classes serialize as objects ({"i": 1}) by defaultCaseClass1ToValueClassmixed in, they still serialize flat (1) — matching the Scala 3 behavior which has nopreferFlatmechanism at allCaseClass1ToValueClassContext
In kebs 2.x, flattening 1-element case classes was made optional via
CaseClass1ToValueClass. However, the Scala 2 macros hadpreferFlathardcoded totrue, which caused the macro to abort for 1-element case classes and effectively requiredCaseClass1ToValueClassto be mixed in — contradicting the opt-in design.Test plan
CirceFormatNoFlatTests— verifies 1-element case classes serialize as objects withoutCaseClass1ToValueClassSprayJsonFormatNoFlatTests— same for spray-jsonCirceFormatTests(withCaseClass1ToValueClass) still pass — flat format preservedSprayJsonFormatTests(withCaseClass1ToValueClass) still pass — flat format preservedcirceSupport/test(76 tests) andsprayJsonSupport/test(90 tests) pass