The accepted answer does not check the constructor no args; following:
public static void checkGwtSerializability(Object o) throws RuntimeException { HostedModeClientOracle hmco = new HostedModeClientOracle(); HasValues command = new ReturnCommand(); HasValuesCommandSink hvcs = new HasValuesCommandSink(command); CommandServerSerializationStreamWriter out = new CommandServerSerializationStreamWriter(hmco, hvcs); try { out.writeObject(o); } catch (SerializationException e) { throw new RuntimeException("Object not serializable: " + o + " Caused by: " + e.getMessage(), e); } try { o.getClass().getDeclaredConstructor(); } catch (NoSuchMethodException e) { throw new RuntimeException("Object not serializable: " + o + " Caused by: " + e.getMessage(), e); } }
source share