Changelog
0.2.0 (unreleased)
Added
- JSON names:
generateJsonFields/@mokaJsonbuild aJsonFieldsobject from zio-json's@jsonField.generateFieldsstays BSON-only. - Explicit BSON selector:
generateBsonFields/@mokaBson(BsonFields). - Format markers: generated objects are typed
MokaBsonNames,MokaJsonNamesorMokaNames(nothing renamed). Details. - Scala 2.13:
@moka(name = "X"), and stacking@moka @mokaBson @mokaJson. - A warning when a type is renamed only by the other format's annotations
(e.g.
@jsonFieldundergenerateFields). - Scala 2.13: one error lists every nested type missing its moka object; a nested type whose own expansion failed is reported as such.
Fixed
- Scala 2.13:
@bsonFieldon a nested type compiled in another module, jar or incremental build was silently dropped, giving a wrong path. - Java
@BsonProperty(value = "x")with named arguments. @BsonProperty("")keeps the field name instead of producing"".- Scala 2.13: meta-annotated renames such as
@(BsonProperty @field)("x")were ignored, on the annotated class and, under the opt-out, on nested types. - Scala 2.13: a type declared beside the annotated class, sharing its name with an outer type, silently produced the outer type's names; it is now an error.
- Scala 2.13:
@mokaon a generic case class gives a clear error. - Scala 2.13: mutually recursive case classes give a clear error naming the
cycle instead of crashing the compiler with
StackOverflowError. - Scala 3:
generateFieldson a type alias of a case class. - Scala 3: a root with thousands of nested fields failed to compile with
Method too large; the tree is now emitted as string constants, which also roughly halves moka's compile-time overhead on large models. IntMapandLongMapfields were descended into as collections; likeMap, they are now leaves.- A generic type nested in itself (
Box[Box[X]]) stopped at the innerBoxas if it were a cycle. - Scala 2.13: a field typed as another package's class of the same name
(
case class Event(prev: legacy.Event)) was a leaf; it is now composed, as on Scala 3. - Scala 2.13: a nested node two levels below a type from another run became a plain string.
- Scala 2.13: a node's
toStringwas an object reference; on both versions it is now its path, sos"${node}.x"works. - Scala 2.13: a field type that does not resolve (a typo, a missing import) reported the sibling-type limitation instead of the compiler's own error.
- Scala 2.13: an invalid regex in
@nowarn("msg=...")crashed the macro. - Scala 3: renaming conflicts and the other-format warning point at the field
instead of the
generateFieldscall. To silence that warning, put@nowarnon the case class or the field, as on Scala 2.13; on theval Fields = generateFields[...]placeholder it no longer applies.
Breaking changes and migration
Scala 2.13 only: every nested case class needs its own moka object, in the outer's format (one with no renames serves both formats):
@moka
final case class Engine(@bsonField("hp") power: Int)
object Engine {
val Fields = generateFields[Engine]
}
Otherwise compilation fails with moka: nested types without a BSON moka object. Rebuild models compiled with moka 0.1.x. For types you cannot annotate,
or generic ones, compile with -Xmacro-settings:moka.descendUnannotated
(opting out).
On both versions:
- Two renames of the same format that disagree on one field are a compile error (0.1.0 used the first). Keep one.
- Scala 2.13: a companion member named like a generated object (e.g. your own
object Fields) is a compile error. Rename it. - An
IntMap/LongMapfield is a leaf:m.x,m._matchedandm._allno longer exist. Address its values as with anyMap. Box[Box[X]]descends into the innerBox, so its field is a node: useb._pathwhere the field itself was used as a string.- Scala 2.13: a field typed as another package's same-named class is a node (or needs that class's moka object), not a leaf.
After changing a renaming annotation, do a clean build: code in other files keeps the old name otherwise (stale names).
See also known limitations.
0.1.0 (2026-08-28)
Initial release.