Skip to content
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

Support default values for case class fields #593

Merged
merged 12 commits into from
Jun 11, 2024
Prev Previous commit
Next Next commit
add a test for case class field defaults
  • Loading branch information
mberndt123 committed Jan 14, 2024
commit 74962aa14618ab8c36bcf271b0b23b55fd3c9cd2
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ lazy val generic = project
scalaSettings ++ Seq(
crossScalaVersions += scala3
),
scalacOptions += "-Yretain-trees",
testSettings
)
.dependsOn(core % "compile->compile;test->test")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2019-2023 OVO Energy Limited
*
* SPDX-License-Identifier: Apache-2.0
*/

package vulcan.generic

import vulcan.Codec

case class Foo(
a: Int = 1,
b: String = "foo",
)

object Foo {
implicit val codec: Codec[Foo] = Codec.derive
}

final class AvroFieldDefaultSpec extends CodecBase {
describe("AvroFieldDefault") {
it("should create a schema with a default for a field") {

assert(Foo.codec.schema.exists(_.getField("a").defaultVal() == 1))
assert(Foo.codec.schema.exists(_.getField("b").defaultVal() == "foo"))
}
}
}