i have a function which takes a list of objects as a parameter, takes out each object from the list and makes json object with its attributes and then add the json object to a mutable list and returns it
class foo {
var jsonlist = new MutableList[JsValue]
def makeJson(objlist : List[Student]) : MutableList[JsValue] = {
for( obj <- objlist){
var jsobj = Json.obj("name" -> obj.getName, "uuid" -> obj.getUuid)
jsonlist += jsobj
}
jsonlist
}
}
i need this fucntion in different classes with and different parameter type for List i.e List[Teacher], List[Admin] etc
Is there any way of writing this function so that i can use it for different classes or i have to write it separately for every class?
if it is not possible than, i have a User trait and some classes that extends User Trait . Can i write the above code in a way that can be used by all the child classes