Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created February 15, 2018 17:59
Show Gist options
  • Save kmizu/9b38282c6bdc59e422ae7a576162e9e8 to your computer and use it in GitHub Desktop.
Save kmizu/9b38282c6bdc59e422ae7a576162e9e8 to your computer and use it in GitHub Desktop.
SAM-convertible type and Function type
sbt.version=1.1.0
organization := "com.github.kmizu"
name := "play-json-example"
version := "0.1-SNAPSHOT"
scalaVersion := "2.12.4"
libraryDependencies += "com.typesafe.play" %% "play-json" % "2.6.7"
package com.github.kmizu.play_json_example
import play.api.libs.json._
object Main {
implicit class RichWrites[A](w: Writes[A]) {
def ignore(ignoreFields: String*): Writes[A] = {
w.transform{
case JsObject(fields) => JsObject(fields.filterNot {
case (k, _) => ignoreFields.contains(k)
})
case json => json
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment