title: Scala conditional None value assignment
body: <p>I am trying to convert com.google.gson.JsonObject to case class object. Sometime some element in the record are missing in which case I want it to be assigned as None to case class member</p>
  
  <pre><code>object tmp {
    case class person(name: String, age: Long)
    def main(args: Array[String]): Unit = {
     val parser = new JsonParser();
  
     //PERSON 2
     val record2 = parser.parse("""{"name":"xyz"}""").getAsJsonObject()
  
     val record2_name = record2.get("name").getAsString.toLowerCase
     val record2_age = if(record2.get("age") != null) record2.get("age") else None
  
     val person2 = new person(record2_name,record2_age)  //-&gt; Type Mismatch, expected: Long, actual: Long
  
     println(person2);
  
    }
  }
  </code></pre>