I am trying to create my own library for serializing and de-serializing primitive types from a class in xml and from xml to an instance of a class using reflection to examine method naming patterns and return method types.
So far, I could do this with all the basic primitive types, but I'm stuck in serializing an array with the same primitives.
For example, I call a class method to get an array of primitives:
method.invoke(clazz, (Object[])null);
This method returns only a primitive array of int[], double[], float[], char[] , etc., although we do not know which one it will be.
I tried using a generic type like
T t = (T)method.invoke(clazz, (Object[])null); T[] t = (T[])method.invoke(clazz, (Object[])null);
But this does not allow me to convert from a primitive array to an object.
And you cannot use Array.newInstance if you don't know the type.
Is there a way I can convert this array of primitives to say an array of objects in a general way.
In a general sense, this means that you do not need to know or check the type of the array. Or should I just iterate over all the primitive types and process them all separately.
I can do this in both directions, the only reason I want to do it in a general way is to reduce redundant code.
Thanks in advance.