mardi 23 octobre 2018

Scala deserialize class dynamically using Gson

I am working in scala programming language

I want to deserialize json to a case class dynamically. So my v1 code is

  protected def DeSerializeJson(json: String): MyClass= {    
    val gson = new Gson
    val response = gson.fromJson(json, classOf[MyClass])
    response
  }

The above code only de-serializes json to MyClass. I want to make it reusable for other class as well with an extra argument of class type. so that I can pass different json and different type and it will return that particular class object. But I am not able to figure out the variable type of second parameter and how to call it. Can someone please help?

Thanks





Aucun commentaire:

Enregistrer un commentaire