Created
October 31, 2013 15:27
-
-
Save jrudolph/7251633 to your computer and use it in GitHub Desktop.
ToLowerCase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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