Must we use @JsonProperty in Scala case classes?

北慕城南 提交于 2019-12-12 03:31:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!