Formatting case classes with dynamic default arguments

(moving the discussion here from Gitter)

Hey everyone,
I have a question about deserializing case classes with dynamic default values using Json.WithDefaultValues
let’s say we have a class

case class Test(
  id: Int = new ObjectId(),
  someField: String
)

object Test {
  private implicit val config = JsonConfiguration[Json.WithDefaultValues](JsonNaming.SnakeCase)
  implicit val testFormat = Json.format[Test]
}

The problem is that default value for test argument seems to be cached by Play, so Json.parse("""{"some_field": "text"}""").validate[Test] will always return the same value for id field.

Is there any way to fix this? Some workaround maybe?

1 Like

Turns out it’s already fixed in the latest version (which I obviously should have checked before anything else >_<)

1 Like

Hi Alex, I had the same issue which totally threw me as I thought it was an issue with latest version of Lagom until I dug deeper. Do you have any reference to the bug? I would like to notify the Lagom team of this.