I am not sure if I am doing some silly mistake, What I am trying to achieve is I have JSON list and I want to convert them into multiple objects depending on variable argument passed to function.
Unit u1= new Unit();
User us = new User();
//calling funtion
StaticUtil.MagicJsonMapper(list, u1,us);
System.out.println(u1.getUnitName()); //place -1 unitName is null after function call
Inside static class I have create a function
@SuppressWarnings("rawtypes")
public static void MagicJsonMapper(List list,Object... objects){
if(list.size()!= objects.length){
//TODO
System.out.println("parame`ter mismatch");
return;
}
int i=0;
ObjectMapper mapper = new ObjectMapper();
for(Object object : objects){
if(list.get(i) instanceof List){
MagicJsonMapper((List)list.get(i),object);
}
else{
objects[i] = mapper.convertValue(list.get(i), object.getClass());
}
i++;
}
//place -2 "objects" contains proper value of unitname
}
The issue is I am still not getting proper value in parameter after finished running this method. It means argument values are not retained as in contrast of normal java behaviour, is it something to do with variable argument. Just for clarity I debugged the code and values are proper at the end of the function.