0

everyone.

This seems to be quite an unnecessary exercise to define the @JsonProperty annotations for Json serialization of a case class. For example:

case class Foo @JsonCreator()(
  @JsonProperty("a") a: String,
  @JsonProperty("b") b: Boolean,
  @JsonProperty("c") c: Int)

It appears that the trivial @JsonProperty annotations like this (just repeating the parameter's name) can be avoided in Java, by using the jackson-module-parameter-names module and the -parameters javac option:

Why when a constructor is annotated with @JsonCreator, its arguments must be annotated with @JsonProperty?

However, that doesn't work with Scala case classes. Is there a solution to this?

Community
  • 1
  • 1
silverberry
  • 786
  • 5
  • 20
  • Are you using same version of `jackson-module-scala` as `jackson-core`? I believe the use of the annotation is unnecessary when the property name is same as the field name. – jacks Mar 10 '17 at 21:58
  • I'm just using the Jackson modules that come with Lagom by default. I'll check. Thanks! – silverberry Mar 11 '17 at 17:19

1 Answers1

0

Right. It turns out Lagom doesn't include jackson-module-scala by default.

silverberry
  • 786
  • 5
  • 20