title: In scala, how to turn object's values into Map[String, String]?
body: <p>Let's say that I have this class </p>
  
  <pre><code>case class Test (id: Long, name: String)
  </code></pre>
  
  <p>and an instance of this class :</p>
  
  <pre><code>Test :
  id -&gt; 1
  name -&gt; toto
  </code></pre>
  
  <p>I would like to create a Map[String, String] as follow :</p>
  
  <pre><code>Map( "id" -&gt; "1", "name" -&gt; "toto")
  </code></pre>
  
  <p>My question is : Is there a way to turn this instance of Test into Map[String, String]  ? I want to avoid to use a method as this one :</p>
  
  <pre><code>def createMap(instance: Test): Map[String, String] = {
      val map = new Map[String, String]
      map.put("id", instance.id.toString)
      map.put("name", instance.name)
      map
  }
  </code></pre>
  
  <p>If there is no method to do so in Scala, is there a way to iterate over class properties ? Maybe I can create a generic function to do so :</p>
  
  <pre><code>def createMap(instance: T): Map[String, String] = {
     val map = new Map[String, String]
     //pseudocode 
     for  ((name, value) &lt;- instance.getClassProperties.getValues) {
        case value.isInstanceOf[String] : map.push(name, value)
        case _ : map.push(name, value.toString)
      }
      map
  }
  </code></pre>
  
  <p>Is that possible ? If you have good examples/links, I'm interested.</p>