This content has been marked as final.
Show 1 reply
-
1. Re: ManagedProperty serialization issue
alesj Oct 5, 2007 7:44 AM (in response to alesj)"alesj" wrote:
I guess this should be added (or is this even part of what I was changing with implementing serialization to ClassInfo?), although it looks like an ugly implementation is about to come out of this. :-)
I added this to ReflectMethodInfoImpl (+ similar code to other ReflectX classes):private void readObject(ObjectInputStream oistream) throws IOException, ClassNotFoundException, NoSuchMethodException { oistream.defaultReadObject(); int length = parameterTypes != null ? parameterTypes.length : 0; Class<?>[] classes = new Class<?>[length]; for(int j = 0; j < length; j++) classes[j] = parameterTypes[j].getType(); method = ReflectionUtils.findExactMethod(getDeclaringClass().getType(), name, classes); }
Utils code:public static Method findMethod(Class clazz, String name, Class<?>... parameterTypes) { if (clazz == null) return null; try { return clazz.getDeclaredMethod(name, parameterTypes); } catch(Exception ignored) { } return findMethod(clazz.getSuperclass(), name, parameterTypes); } public static Method findExactMethod(Class clazz, String name, Class<?>... parameterTypes) throws NoSuchMethodException { Method method = findMethod(clazz, name, parameterTypes); if (method == null) throw new NoSuchMethodException(clazz + "." + name + " - " + Arrays.asList(parameterTypes)); return method; }
Which makes ReflectX classes know their Member instance after deserialization.