StacktraceElement is marked as transient to keep it out of serialization. Because of that, RPC system is not aware of the type. If you really want to transfer the stack trace with your exception, then put a dummy field in your exception:
private StackTraceElement dummyFieldToIncludeType; This will make StackTraceElement visible for serialization. On Mon, May 13, 2013 at 2:14 PM, <[email protected]> wrote: > Hi guys, > > I am unable to serialize my own Exception class. I have created an > exception class as follows: > > public class KeyNotFoundException extends java.lang.Exception { > private String key; > private String resourceBundleName; > > /** > * The key was not found in the resource bundle > * > * @param resourceBundleName The resource bundle name > * @param key The key > */ > public KeyNotFoundException(String resourceBundleName, String key) { > super("The resource bundle '" + resourceBundleName + "' does not > have the key '" + key + "'"); > this.resourceBundleName = resourceBundleName; > this.key = key; > } > > /** > * Get the key > * > * @return The key > */ > public String getKey() { > return key; > } > > /** > * Get the resource bundle name > * > * @return The resource bundle name > */ > public String getResourceBundleName() { > return resourceBundleName; > } > } > > This obviously needs a CustomFieldSerializer, so I created this one: > > public class KeyNotFoundException_CustomFieldSerializer extends > CustomFieldSerializer<KeyNotFoundException> { > /** > * Deserialize the KeyNotFoundException from the stream > * > * @param streamReader The stream that contains the > KeyNotFoundException > * @param instance The instance to stream the details to > * @throws SerializationException If unable to deserialize the instance > */ > public static void deserialize(SerializationStreamReader streamReader, > KeyNotFoundException instance) throws SerializationException { > instance.setStackTrace((StackTraceElement[]) > streamReader.readObject()); > } > > /** > * Create a new instance of a KeyNotFoundException from the stream > * > * @param streamReader The stream that contains the > KeyNotFoundException > * @return The KeyNotFoundException > * @throws SerializationException If unable to serialize the instance > */ > public static KeyNotFoundException > instantiate(SerializationStreamReader streamReader) throws > SerializationException { > String resourceBundleName = streamReader.readString(); > String key = streamReader.readString(); > return new KeyNotFoundException(resourceBundleName, key); > } > > /** > * Serialize the KeyNotFoundException to the stream > * > * @param streamWriter The stream to serialize the > KeyNotFoundException to > * @param instance The KeyNotFoundException to serialize > * @throws SerializationException If unable to serialize the instance > */ > public static void serialize(SerializationStreamWriter streamWriter, > KeyNotFoundException instance) throws SerializationException { > // Serialize the constructor parameters > streamWriter.writeString(instance.getResourceBundleName()); > streamWriter.writeString(instance.getKey()); > > // Serialize instance variables > streamWriter.writeObject(instance.getStackTrace()); > } > > @Override > public void deserializeInstance(SerializationStreamReader > streamReader, KeyNotFoundException instance) throws SerializationException { > deserialize(streamReader, instance); > } > > @Override > public boolean hasCustomInstantiateInstance() { > return true; > } > > @Override > public KeyNotFoundException > instantiateInstance(SerializationStreamReader streamReader) throws > SerializationException { > return instantiate(streamReader); > } > > @Override > public void serializeInstance(SerializationStreamWriter streamWriter, > KeyNotFoundException instance) throws SerializationException { > serialize(streamWriter, instance); > } > } > > This does not work. The StackTraceElement is not whitelisted. What do I > need to do to get this working correctly! Its very frustrating! > > > -- > You received this message because you are subscribed to the Google Groups > "Google Web Toolkit" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
