amnaredo / test

0 stars 0 forks source link

Add null-safe helper functions with ujson.Value#{str,num,obj,arr,bool} #250

Open amnaredo opened 2 years ago

amnaredo commented 2 years ago

e.g. .strOpt: Option[String], which would return None if the thing is ujson.Null ID: 266 Original Author: lihaoyi-databricks

amnaredo commented 2 years ago

Using upickle 0.8.0: My expectation was document("xyz").strOpt would now return None if the key does not exist at all in the document. Instead it blows up on me with an Unexpected exception[NoSuchElementException: key not found: xyz

Currently I have to surround any key access that could go wrong with a try/catch, wouldn't it be nice if this case was also handled safely as an Option?

Original Author: nemoo

amnaredo commented 2 years ago

@nemoo maybe this val newStartLine = document.obj.get("xyz").map(_.str) will work around. Original Author: lust4life