Hi..my aim is to serialize/deserialize my "SoapPair" class , that contains Axis MessageContext obj (SoapPair receives this from its constructor), not serializable object(when trying to normally serialize , it returns "axis MessageContext not serializable")..
How do I serialize/deser the SoapPair class?
Do I have to use SerializationContext/Deser context? How?
Thanks in Advance.

Recommended Answers

All 7 Replies

Can you post your codes ? How about WSDL ?

Can you post your codes ? How about WSDL ?

I'll show you the skeleton of SoapPair class. It receives from the constructor an Axis MessageContext (it's not manadatory...)..and from it divides the Soap message into header+body (2 get methods).
My aim is to serialize that class from a test main , using the 2 methods deserialize/serialized that I should override in the class.

public class SoapPair{    
 
public SoapPair(org.apache.axis.MessageContext mc) {}
 
public Message getLeft(){
	return leftmsg
}
 
public Message getRight(){
return rightmsg;
}
 

protected void _serialize(final OutputStream out) throws PostException {
}
 

public Message deSerialize(final InputStream in) throws PostException {
}

If your SoapPair class has any member variables, all of them have to be of a type that is serializable.

Yes I know that...
the problem is that "MessageContext" of Axis is NOT serializable...

You need to mark the field of type MessageContext as transient so that the serialization mechanism doesn't attempt to serialize it. This only works if the state of the MessageContext has no significance whatsoever to the newly reconstituted SoapPair object. If it does, then you have to manually write out the state of the MessageContext object for which you will have to provide an implementation for readObject and writeObject methods for your SoapPair class.

But given that if the MessageContext class isn't Serializable , there might be a good reason behind it. Are you sure the MessageContext instance *really* constitutes the state of your SoapPair object? Also given that any context logically belongs to a given environment, serializing it or clubbing it with something which is meant to be serialized doesn't make much sense.

Thanks for reply....my professor keep on telling me that I have to implement ser/deser methods using Axis's (vers.1) ...Like serialization context and so on...but I don't know from how to start..
Thanks in Advance

I haven't worked with Axis so wouldn't know the context involved but like I previously suggested, either mark the field as transient or implement your own readObject and writeObject methods to get around the restriction. Search for 'serialization java' with the search engine of your choice and you should find something to get you started.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.