假设我有一个像这样的json写
implicit val userWrites: Writes[User] = (
(__ \ "name").write[String] ~
(__ \ "email").write[String] ~
(__ \ "encryptedPassword").write[String] ~
(__ \ "id").writeNullable[Long]
)(unlift(User.unapply))
如果我不想打印输出密码,而只是打印字符串"hidden"
,我怎么能用组合器实现这个目标?
我正在寻找与此相似的解决方案
implicit val userWrites: Writes[User] = (
(__ \ "name").write[String] ~
(__ \ "email").write[String] ~
(__ \ "encryptedPassword").write[String](Writes.pure("hidden")) ~
(__ \ "id").writeNullable[Long]
)(unlift(User.unapply))
答案 0 :(得分:2)
你可以这样做:
InetAddress.getByName("089.108.003.152").getHostAddress();
答案 1 :(得分:1)
这应该有效:
implicit val userWrites: Writes[User] = (
(__ \ "name").write[String] ~
(__ \ "email").write[String] ~
(__ \ "encryptedPassword").write[String](Writes((_: String) => JsString("hidden"))) ~
(__ \ "id").writeNullable[Long]
)(unlift(User.unapply))