title: Reading YAML in Scala without 'case class'
body: <p>I am trying to read <code>YAML</code> file from <code>Scala</code> and I am able to read the file using the code given below. One of the disadvantage I see here is the necessity for me to create <code>case class</code> to have a mapping with the <code>YAML</code> file I am using. Every time I change the content of <code>YAML</code> it becomes necessary for me to change the <code>case class</code>. Is there any way in Scala to read <code>YAML</code> <strong><em>with out</em></strong> the need for me to create the <code>case class</code>. (I have also used <code>Python</code> to read <code>YAML</code> ; where we do not have the constraint of mapping a <code>Class</code> with the <code>YAML</code> structure...and would like to do similar thing in <code>Scala</code>)</p>
  
  <p><strong>Note</strong> : When I add a new property in <code>YAML</code> and if my <code>case class</code> do not have a matching property I get <code>UnrecognizedPropertyException</code></p>
  
  <pre><code>package yamlexamples
  
  import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
  import com.fasterxml.jackson.databind.ObjectMapper
  import com.fasterxml.jackson.module.scala.DefaultScalaModule
  
  object YamlTest extends App{
  
  
    case class Prop(country: String, state: List[String])
  
    val mapper: ObjectMapper = new ObjectMapper(new YAMLFactory())
  
    mapper.registerModule(DefaultScalaModule)
    val fileStream = getClass.getResourceAsStream("/sample.yaml")
    val prop:Prop = mapper.readValue(fileStream, classOf[Prop])
  
    println(prop.country + ", " + prop.state)
  
  }
  </code></pre>
  
  <p><code>sample.yaml</code>(This works with code)</p>
  
  <pre><code>country: US
  state: 
    - TX
    - VA
  </code></pre>
  
  <p><code>sample.yaml</code> (This throws Exception)</p>
  
  <pre><code>country: US
  state: 
    - TX
    - VA
  continent: North America
  </code></pre>