我们必须在Scala案例类中使用@JsonProperty吗? [英] Must we use @JsonProperty in Scala case classes?

查看:229
本文介绍了我们必须在Scala案例类中使用@JsonProperty吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有人.

为案例类的Json序列化定义@JsonProperty批注似乎是不必要的练习.例如:

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)

通过使用 jackson-module-parameter-names 模块和-参数 javac选项:

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:

为什么在使用@JsonCreator注释构造函数时,必须使用@JsonProperty注释其构造函数?

但是,这不适用于Scala案例类.有解决办法吗?

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

推荐答案

正确.事实证明,Lagom默认不包含 jackson-module-scala .

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

这篇关于我们必须在Scala案例类中使用@JsonProperty吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆