问题
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?
回答1:
Right. It turns out Lagom doesn't include jackson-module-scala by default.
来源:https://stackoverflow.com/questions/42726339/must-we-use-jsonproperty-in-scala-case-classes