private Object instantiate(Class<?> customSerializer, Class<?> instanceClass)
throws InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SerializationException {
if (customSerializer != null) {
CustomFieldSerializer customFieldSerializer =
SerializabilityUtil.loadCustomFieldSerializer(customSerializer);
if (customFieldSerializer == null) {
for (Method method : customSerializer.getMethods()) {
if ("instantiate".equals(method.getName())) {
return method.invoke(null, this);
}
}
// Ok to not have one.
} else if (customFieldSerializer.hasCustomInstantiateInstance()) {
return customFieldSerializer.instantiateInstance(this);
}
}
if (instanceClass.isArray()) {
int length = readInt();