Perhaps the proper fix here is to change the api so that data is declared:

     def encode(data: Map[String, Option[String]]): String = {

We don't like nulls in general, so we should pass None instead of Null.