SerializationException when Calling Java Methods that Return a Java Object |
|
Contents
- SYMPTOMS
- CAUSE
- RESOLUTION
SYMPTOMS
When calling a Java method from a .NET client that returns another Java object, the following exception occurs:
CAUSE
The Java object being returned implements the Java interface java.io.Serializable. Because of this, the J-Integra for .NET runtime will automatically try to send a serialized version of the object back to the .NET client. However, the object has not been generated with the "Pass by Value" option using GenNet, and the exception is thrown.
RESOLUTION
There are two different solutions, depending on whether you intended for the returned object to be serializable or not.
To have the method return a serializable object:
- Launch GenNet again, and click Next to see the list of classes.
- Highlight the object being returned from the method, and click on "Options..."
- Click the "Pass by Value" checkbox, and then click OK.
- Continue with GenNet to re-generate the C# proxies.
- Run your client again and this time it should work as expected.
- Keep in mind that Serializable objects only expose public data fields!
To have the method return a NON-serializable object:
- Launch Janetor again, and highlight the "Local Objects".
- Right-click the mouse button and select Add.
- Enter the fully qualified name of your Java object that is being returned by the method and then click OK.
- Make sure that the "Pass by Reference" checkbox is checked for this class.
- For the URI and "Assembly Name" entries, copy/paste the same data from the default node (unless your Java object is located at a different URI or assembly).
- Run your client again and this time it should work as expected.