Play Framework: How to serialize/deserialize an enumeration to/from JSON

前端 未结 5 1171
有刺的猬
有刺的猬 2020-12-29 20:43

Given the following enumeration...

object MyEnum extends Enumeration {

  type MyEnum = Value

  val Val1 = Value(\"val1\")
  val Val2 = Value(\"val2\")
  va         


        
5条回答
  •  时光说笑
    2020-12-29 21:06

    Try changing it to

    def reads(json: JsValue) = JsSuccess(MyEnum.withName(json.as[String].value))
    

提交回复
热议问题