Skip to content

Instantly share code, notes, and snippets.

@jrudolph
Created October 31, 2013 15:27
Show Gist options
  • Save jrudolph/7251633 to your computer and use it in GitHub Desktop.
Save jrudolph/7251633 to your computer and use it in GitHub Desktop.
ToLowerCase
object Test extends App {
import DefaultJsonProtocol._
trait ToLowerCase
object ToLowerCase {
def apply(str: String): String with ToLowerCase = str.toLowerCase.asInstanceOf[String with ToLowerCase]
implicit val strWithToLowerCaseFormat: JsonFormat[String with ToLowerCase] =
new JsonFormat[String with ToLowerCase] {
def write(obj: String with ToLowerCase): JsValue = JsString(obj)
def read(json: JsValue): String with ToLowerCase = ToLowerCase(json.convertTo[String])
}
}
case class User(userId: String with ToLowerCase)
object User {
implicit val userFormat = jsonFormat1(User.apply _)
}
println(JsonParser("""{ "userId": "Joe" }""").convertTo[User])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment