// ------------------------------------------------------------------------- @SuppressWarnings("unchecked") @Override public T buildObject(FudgeDeserializer deserializer, FudgeMsg outerMsg) { FudgeField fudgeField = outerMsg.getByName("inner"); FudgeMsg msg = (FudgeMsg) fudgeField.getValue(); final FudgeField classNameField = msg.getByOrdinal(FudgeSerializer.TYPES_HEADER_ORDINAL); final String className = (String) classNameField.getValue(); try { final List<Object> parameters = newArrayList(); parameters.add(null); // the omitted enclosing object for (FudgeField parameterField : msg.getAllByOrdinal(1)) { parameters.add(deserializer.fieldValueToObject(parameterField)); } return (T) AccessController.doPrivileged( new PrivilegedAction<Object>() { @Override public Object run() { try { final Class<?> innerClass = Class.forName(className); final Constructor<?>[] ctors = innerClass.getDeclaredConstructors(); // We require that inner classes got only one ctor (anonymous inner classes will // do) // in order to avoid disambiguity if (ctors.length == 1) { final Constructor<?> ctor = ctors[0]; ctor.setAccessible(true); // solution Object inner = ctor.newInstance(parameters.toArray()); return new AutoFudgable<Object>(inner); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } return null; } }); } catch (RuntimeException ex) { throw new FudgeRuntimeException("Unable to deserialize: " + className, ex); } }