title: How to use strings as type without hardcoding them?
body: <p>I have some code to convert json string to objects like following:</p>
  
  <pre><code>def apply(line: String): PairEvent = {
      val (name, json) = line.span(_ != ' ')
      name match {
        case "OpenTabEvent" =&gt; Serialization.read[OpenTabEvent](json)
        case "CloseTabEvent" =&gt; Serialization.read[CloseTabEvent](json)
        case "ChangeContentEvent" =&gt; Serialization.read[ChangeContentEvent](json)
        case "ChangeMasterRequest" =&gt; Serialization.read[ChangeMasterRequest](json)
        case "CreateFileEvent" =&gt; Serialization.read[CreateFileEvent](json)
        case "DeleteFileEvent" =&gt; Serialization.read[DeleteFileEvent](json)
        case "CreateDirEvent" =&gt; Serialization.read[CreateDirEvent](json)
        case "DeleteDirEvent" =&gt; Serialization.read[DeleteDirEvent](json)
        case "WatchingFiles" =&gt; Serialization.read[WatchingFiles](json)
        case _ =&gt;
          ServerLogger.info("!!!!!!!!!!!!!!!!!!!!! unknown line from server: " + line)
          ???
      }
    }
  </code></pre>
  
  <p>You can see I hardcoded some strings and use them as types to convert to objects.</p>
  
  <p>Is there any way to do the same without hardcode them? I'm not sure if it's possible, even with macro.</p>