I need to create a function which is accepting two objects of same class. One is the updated object and other one is the old object. I need to find the differences in updated object by considering the old object. Like we have getDeclaredFields method in java to fetch all the variables.I am seeking for a way to get all the fields of an object and then i have to iterate one by one field and on the basis of its type i have to check equals on both the objects.
// code from comment included:
def trackChanges(newRecord:Object,oldRecord:Object) :String = {
val fields :Array[Field] = newRecord.getClass.getDeclaredFields
var check : String = "Equal"
for( i <- 0 to fields.length-1) {
fields(i).setAccessible(true)
val fieldType:Object = fields(i).getType
fieldType match {
case x: String => fields(i).get(newRecord).equals(fields(i).get(oldRecord))
case x: java.lang.Double => println("String")
case x: Seq[] => println("String")
case x: List[] => }