0

I have the following case class.

case class STUDENT(studentName:String,marks:Array[String],gender:String,mobileNumber:Option[String])

and i have the following Json string.

"studentName": "test_filter",
"marks":"['10','20']",
"gender":"M",
"mobileNumber": "*****"

and the below function that parse the string,actual i am passing json as string.

 def readStudentConfig(config:String) :STUDENT ={
   val gson = new Gson()
    gson.fromJson(config,classOf[STUDENT])
  }

But its return me an error like

Failed to invoke public scala.Option() with no args

Edit question for better understanding.

and i have the following Json string.If i pass the mobileNumber the parser is working(need to change datatype case class last paramter to String)

{ 
"studentName": "test_filter",
"marks":"['10','20']",
"gender":"M",
"mobileNumber": "*****" 

}

If i blank the mobileNumber i.e "mobileNumber":''; the code will break. like that

    { 
    "studentName": "test_filter",
    "marks":"['10','20']",
    "gender":"M",
    "mobileNumber": "" 
   }

0 Answers0