playframework/Play20 — pull request #252 by leon (2012-04-21 15:22:54+00:00)
Title: JSON Enumeration support

To support Enumerations when deserializing JSON we need to specify the type of the enum.

It's the same problem as with the form enum support.

I've added a spec from the start this time, and squashed the commits :)

import play.api.libs.json.Reads.enum
object Status extends Enumeration {
val Free = Value("free")
}

val e = Status.Free
val m = Map("status" -> e)
val jsonM = toJson(m)
(jsonM \ "status").as(enum(Status)) must equalTo(e)