Hello all,

I'm having problems bypassing the servlet and deserializing an XML string using 
the axis libraries.  I was able to serialize the data, but the deserialization 
posed more of a problem.

In the code snippet below I'm able to serialize the object into an XML string.  
I am then unable to take that same string and de-serialize it.

Any ideas would be appreciated.

-mike

------------------------------

+class Datasheet {
  ArrayList[] entities;
  ArrayList[] attribs;
}


// ++++++++++++++++++++++++++++++++++++++++++++++++++++
try {

	Service service = new Service();			
	call = (Call) service.createCall();
	
	for (int i = 0; i < qnames.length; i++) {
		QName qname = qnames[i];
		//get the local part of the qname 
		String localPart = qname.getLocalPart();
		//need the class for registration
		Class theClass =
			Class.forName("my.org.webservice.model." + localPart);

		if (localPart.equals("EntityKeys")) {
			//register the types for serialization / deserialization
			call.registerTypeMapping(
				theClass,
				qname,
				new EnumSerializerFactory(theClass, qname),
				new EnumDeserializerFactory(theClass, qname));
		} else {
			//register the types for serialization / deserialization
			call.registerTypeMapping(
				theClass,
				qname,
				new BeanSerializerFactory(theClass, qname),
				new BeanDeserializerFactory(theClass, qname));
		}
	}
	
	String strT = null;
	StringWriter writer = new StringWriter();
	SerializationContext context = new SerializationContextImpl(writer, 
		call.getMessageContext());
	context.setDoMultiRefs(false);
	context.setPretty(true);
	//do the actual serialization
	context.serialize(qnames[2], new 
		org.xml.sax.helpers.AttributesImpl(), sheet);
	//flush the stream
	writer.flush();	
	//return the string
	strT = writer.toString();	
	
	// +++++++++ Serialization of "sheet" of type Datasheet 
        // works wonderfully.		
	// +++++++++ Deserialization creates an an empty Datasheet object.
	
	// seems like top level object needs to be "Envelope"
	putInSoapEnvelope(strT);
	
	// Put string into a Stream
	ByteArrayInputStream s =
		new ByteArrayInputStream(strT.getBytes());
	inputSource = new InputSource(s);

	DeserializationContext context =
		new DeserializationContextImpl(
			inputSource,
			call.getMessageContext(),
			"Datasheet");	
			
	context.parse();
	
	while (!context.isDoneParsing());
	
	((DeserializationContextImpl)context).startElement
			(namespace, "Envelope", "Envelope", )			
							
	
	Class dataSheetClass = Class.forName
		("my.org.webservice.model.Datasheet");
	Deserializer deserializer = 
		context.getDeserializer(dataSheetClass, qnames[2]);
		
	deserializer.startElement(namespace, "Datasheet", "Datasheet", 
		new AttributesImpl(), context);
	
	ds = (Datasheet)deserializer.getValue();

} catch (Exception e) {
	e.printStackTrace();
}

games.inbox.lv - Mario, Car Racer, Tetris, Pool, Chess and 1000s of FREE games! Hey, click, play!

Reply via email to