Case Class Instantiation From Typesafe Config
<p>Suppose I have a scala case class with the ability to serialize into json (using json4s or some other library):</p>

<pre><code>case class Weather(zip : String, temp : Double, isRaining : Boolean)
</code></pre>

<p>If I'm using a <a href="https://github.com/typesafehub/config/blob/master/HOCON.md" rel="noreferrer">HOCON</a> config file:</p>

<pre><code>allWeather {

   BeverlyHills {
    zip : 90210
    temp : 75.0
    isRaining : false
  }

  Cambridge {
    zip : 10013
    temp : 32.0
    isRainging : true
  }

}
</code></pre>

<p><strong>Is there any way to use <a href="https://github.com/typesafehub/config" rel="noreferrer">typesafe config</a> to automatically instantiate a <code>Weather</code> object?</strong>  </p>

<p>I'm looking for something of the form</p>

<pre><code>val config : Config = ConfigFactory.parseFile(new java.io.File("weather.conf"))

val bevHills : Weather = config.getObject("allWeather.BeverlyHills").as[Weather]
</code></pre>

<p>The solution could leverage the fact that the value referenced by <code>"allWeather.BeverlyHills"</code> is a json "blob".  </p>

<p>I could obviously write my own parser:</p>

<pre><code>def configToWeather(config : Config) = 
  Weather(config.getString("zip"), 
          config.getDouble("temp"), 
          config.getBoolean("isRaining"))

val bevHills = configToWeather(config.getConfig("allWeather.BeverlyHills"))
</code></pre>

<p>But that seems inelegant since any change to the Weather definition would also require a change to <code>configToWeather</code>.</p>

<p>Thank you in advance for your review and response.</p>