title: Play Framework: How to serialize/deserialize an enumeration to/from JSON
body: <p>Given the following enumeration...</p>
  
  <pre><code>object MyEnum extends Enumeration {
  
    type MyEnum = Value
  
    val Val1 = Value("val1")
    val Val2 = Value("val2")
    val ValN = Value("valN")
  
    implicit val myEnumFormat = new Format[MyEnum] {
      def reads(json: JsValue) = MyEnum.withName(json.as[String].value) // doesn't compile
      def writes(myEnum: MyEnum) = JsString(myEnum.toString)
    }
  }
  </code></pre>
  
  <p>... I need to serialize/deserialize it to/from JSON. <code>myEnumFormat</code> does not compile and I always get the following error message:</p>
  
  <pre><code>type mismatch;
  [error]  found   : models.MyEnum.Value
  [error]  required: play.api.libs.json.JsResult[models.MyEnumValue]
  [error]  Note: implicit value myEnumFormat is not applicable here because it comes after the application point and it lacks an explicit result type
  [error]     def reads(json: JsValue) = MyEnum.withName(json.as[JsString].value)
  </code></pre>
  
  <p>Am I missing something?</p>