I have third party platform jars of which APIs need to be tested using webservices. These APIs take custom objects which are non serializable. Say for example some of the APIs are like this.
doSomething(CustomId someId, DBLoaderType type, DBFilter filter, boolean exclude) returns java.util.List<SomeNavigationSystem>
But these CustomId
, DBLoaderType
, DBFilter
, SomeNavigationSystem
are not serializable objects.
Is there a way that I need not write any extra classes for all these classes (there is a lot of such classes) to serialize? If I write one wrapper or equivalent DTO for each business class then this will be very unscalable.
If the superclass is Serializable, then by default, every subclass is serializable. Hence, even though subclass doesn't implement Serializable interface( and if its superclass implements Serializable), then we can serialize subclass object.
If Address is null, you can serialize the whole employee even if Address 's type is not serializable. If you mark Address as transient, it will skip trying to serialize Address . This may solve your problem.
To serialize an object means to convert its state to a byte stream so way that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements either the java. io. Serializable interface or its subinterface, java.
An object is serializable only if its class implements the Serializable interface. Thus, if you want to serialize the instances of one of your classes, the class must implement the Serializable interface.
please have a look at the Google gson lib under http://code.google.com/p/google-gson/.
I am not sure if I fully understood your problem, but if you want to serialize objects that do not implement java.io.Serializable you should consider json or one of its implementations. Assuming that your objects are serializable from their 'nature', gson can serializable them into a string. Your web service schema may look ugly later, but it could work. You will end up in sending strings.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With