Object[] as the data source
The model has a property of xxx[] Unknown, in Java, object[] cannot be coerced into xxx[], if the F.set (obj,fieldobj) above, the method reflects the write value, will be an error.
Specific methods:
//obj As Object//ClassKey The name of the member variable for the arrayJava.lang.reflect.Field f =Obj.getclass (). Getdeclaredfield (classkey);//Get Array typeClass Fieldclazz =F.gettype ();if(Fieldclazz.isarray ()) {object[] Arrayobjs= (object[]) value;//object[of deserialization production]//Fieldclazz.getcomponenttype (); Gets the member type of the array//array.newinstance (clazz,length) is equivalent to clazz[] Array = new Clazz[length]; but Clazz is unknown, the latter cannot be usedObject fieldobj =array.newinstance (Fieldclazz.getcomponenttype (), arrayobjs.length); for(intj = 0; J < Arrayobjs.length; J + +) { //methods for writing valuesArray.set (Fieldobj, J, Arrayobjs[j]); } f.set (Obj,fieldobj);}
Array of reflection operations---deserialization trivia