You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Sudhir Sharma <su...@espireinfo.com> on 2007/11/01 05:34:24 UTC

RE: Serialize/Deserialize

Hi,

 

I am also facing the same problem. Can anyone help us out.

Any help will be appreciated. 

 

Thanks & Best Regards,

Sudhir Sharma

  _____  

From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com] 
Sent: Wednesday, October 31, 2007 4:43 PM
To: axis-user@ws.apache.org
Subject: Serialize/Deserialize

 

Axis allows you to serialize an object into XML using a
SerializationContext.  For example,

 

   // serialize the object

  StringWriter strWriter = new StringWriter();

  SerializationContext ctx = new SerializationContext(strWriter,
MessageContext.getCurrentContext());

  ctx.serialize(new QName("MyObjectNamespace",  "MyObject"), null, myObject,
null, Boolean.FALSE, Boolean.FALSE);

  String value = strWriter.toString();

 

Is it possible to use Axis to deserialize this string back into an object of
type MyObject?  If so, can you please provide an example?

 

Regards,
Richard

 

----------------------------------------------------------------------------
-------------------------------
This message is intended for the addressee or its representative only. Any
form of unauthorized use, publication, reproduction, copying or disclosure
of the content of this e-mail is not permitted. If you are not the intended
recipient of this e-mail message and its contents, please notify the sender
immediately and delete this message and all its attachments subsequently.


RE: Serialize/Deserialize

Posted by "Gudla, Natraj (GE Money, consultant)" <na...@ge.com>.
We are using axis2 1.2. Not sure why your complex type does not have factory method. I have verified my complex types and it has factory methods. I understand it is required, as this is how the higer level tags delegate the parsing of child tags using the parse of the lower elements.....
 
 

-----Original Message-----
From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com]
Sent: 01 November 2007 10:35
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize



Wsdl2java creates an object for each complex type in the XSD and we are serializing one of these complex types.  The Java class generated for a complex type implements Serializable and there are no parse methods available.  We are using Axis 1.3.  What version of Axis are you using?

 


  _____  


From: Gudla, Natraj (GE Money, consultant) [mailto:natraj.gudla@ge.com] 
Sent: Thursday, November 01, 2007 10:58 AM
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

 

I didnt quite get when you said. In my scenario i have generated the binding classes using a wsdl, referring some xsds. So i have my top most tag of the xml data as a class generated for me. This has parse methods. Ideally that is how even axis resolves any incoming xml requests when you hit the service. 

 

I am not sure when you said your class does not have factory. What is your scenario? 

-----Original Message-----
From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com]
Sent: 01 November 2007 09:47
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

Thanks for the reply.  On the last line you indicated that LoanRequest is a binding class.  The class which I need to parse was generated by Axis and it only implements Serializable so there is no Factory.parse method available.  Any suggestions?

 


  _____  


From: Gudla, Natraj (GE Money, consultant) [mailto:natraj.gudla@ge.com] 
Sent: Thursday, November 01, 2007 9:40 AM
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

 

This is also possible. All that you require is to build an XMLStreamReader and pass it to the parse method from the factory of your top level class. Check my sample code below. I created a stream reader from a sample xml file, in your case you can figure out to pass a string having the xml. Loan request is a binding class.

 

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

InputSource inputSource = new InputSource("xmldata/LnRq_Accept.xml"); 

Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);

StringWriter sw = new StringWriter();

Transformer serializer = TransformerFactory.newInstance().newTransformer();

serializer.transform(new DOMSource(document), new StreamResult(sw));

XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(sw.toString().getBytes()));

LoanRequest lnReq = LoanRequest.Factory.parse(reader);

-----Original Message-----
From: Sudhir Sharma [mailto:sudhir.sharma.tr@espireinfo.com]
Sent: 01 November 2007 04:34
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

Hi,

 

I am also facing the same problem. Can anyone help us out.

Any help will be appreciated. 

 

Thanks & Best Regards,

Sudhir Sharma


  _____  


From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com] 
Sent: Wednesday, October 31, 2007 4:43 PM
To: axis-user@ws.apache.org
Subject: Serialize/Deserialize

 

Axis allows you to serialize an object into XML using a SerializationContext.  For example,

 

   // serialize the object

  StringWriter strWriter = new StringWriter();

  SerializationContext ctx = new SerializationContext(strWriter, MessageContext.getCurrentContext());

  ctx.serialize(new QName("MyObjectNamespace",  "MyObject"), null, myObject, null, Boolean.FALSE, Boolean.FALSE);

  String value = strWriter.toString();

 

Is it possible to use Axis to deserialize this string back into an object of type MyObject?  If so, can you please provide an example?

 

Regards,
Richard

 

-----------------------------------------------------------------------------------------------------------
This message is intended for the addressee or its representative only. Any form of unauthorized use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail message and its contents, please notify the sender immediately and delete this message and all its attachments subsequently.


RE: Serialize/Deserialize

Posted by ABBUHL Richard NL <Ri...@atradius.com>.
Wsdl2java creates an object for each complex type in the XSD and we are
serializing one of these complex types.  The Java class generated for a
complex type implements Serializable and there are no parse methods
available.  We are using Axis 1.3.  What version of Axis are you using?

 

________________________________

From: Gudla, Natraj (GE Money, consultant) [mailto:natraj.gudla@ge.com] 
Sent: Thursday, November 01, 2007 10:58 AM
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

 

I didnt quite get when you said. In my scenario i have generated the
binding classes using a wsdl, referring some xsds. So i have my top most
tag of the xml data as a class generated for me. This has parse methods.
Ideally that is how even axis resolves any incoming xml requests when
you hit the service. 

 

I am not sure when you said your class does not have factory. What is
your scenario? 

	-----Original Message-----
	From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com]
	Sent: 01 November 2007 09:47
	To: axis-user@ws.apache.org
	Subject: RE: Serialize/Deserialize

	Thanks for the reply.  On the last line you indicated that
LoanRequest is a binding class.  The class which I need to parse was
generated by Axis and it only implements Serializable so there is no
Factory.parse method available.  Any suggestions?

	 

	
________________________________


	From: Gudla, Natraj (GE Money, consultant)
[mailto:natraj.gudla@ge.com] 
	Sent: Thursday, November 01, 2007 9:40 AM
	To: axis-user@ws.apache.org
	Subject: RE: Serialize/Deserialize

	 

	This is also possible. All that you require is to build an
XMLStreamReader and pass it to the parse method from the factory of your
top level class. Check my sample code below. I created a stream reader
from a sample xml file, in your case you can figure out to pass a string
having the xml. Loan request is a binding class.

	 

	DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();

	InputSource inputSource = new
InputSource("xmldata/LnRq_Accept.xml"); 

	Document document =
documentBuilderFactory.newDocumentBuilder().parse(inputSource);

	StringWriter sw = new StringWriter();

	Transformer serializer =
TransformerFactory.newInstance().newTransformer();

	serializer.transform(new DOMSource(document), new
StreamResult(sw));

	XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(sw.toString().getBytes()));

	LoanRequest lnReq = LoanRequest.Factory.parse(reader);

		-----Original Message-----
		From: Sudhir Sharma
[mailto:sudhir.sharma.tr@espireinfo.com]
		Sent: 01 November 2007 04:34
		To: axis-user@ws.apache.org
		Subject: RE: Serialize/Deserialize

		Hi,

		 

		I am also facing the same problem. Can anyone help us
out.

		Any help will be appreciated. 

		 

		Thanks & Best Regards,

		Sudhir Sharma

		
________________________________


		From: ABBUHL Richard NL
[mailto:Richard.ABBUHL@atradius.com] 
		Sent: Wednesday, October 31, 2007 4:43 PM
		To: axis-user@ws.apache.org
		Subject: Serialize/Deserialize

		 

		Axis allows you to serialize an object into XML using a
SerializationContext.  For example,

		 

		   // serialize the object

		  StringWriter strWriter = new StringWriter();

		  SerializationContext ctx = new
SerializationContext(strWriter, MessageContext.getCurrentContext());

		  ctx.serialize(new QName("MyObjectNamespace",
"MyObject"), null, myObject, null, Boolean.FALSE, Boolean.FALSE);

		  String value = strWriter.toString();

		 

		Is it possible to use Axis to deserialize this string
back into an object of type MyObject?  If so, can you please provide an
example?

		 

		Regards,
		Richard

		 

	
------------------------------------------------------------------------
-----------------------------------
		This message is intended for the addressee or its
representative only. Any form of unauthorized use, publication,
reproduction, copying or disclosure of the content of this e-mail is not
permitted. If you are not the intended recipient of this e-mail message
and its contents, please notify the sender immediately and delete this
message and all its attachments subsequently.


RE: Serialize/Deserialize

Posted by "Gudla, Natraj (GE Money, consultant)" <na...@ge.com>.
I didnt quite get when you said. In my scenario i have generated the binding classes using a wsdl, referring some xsds. So i have my top most tag of the xml data as a class generated for me. This has parse methods. Ideally that is how even axis resolves any incoming xml requests when you hit the service. 
 
I am not sure when you said your class does not have factory. What is your scenario? 

-----Original Message-----
From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com]
Sent: 01 November 2007 09:47
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize



Thanks for the reply.  On the last line you indicated that LoanRequest is a binding class.  The class which I need to parse was generated by Axis and it only implements Serializable so there is no Factory.parse method available.  Any suggestions?

 


  _____  


From: Gudla, Natraj (GE Money, consultant) [mailto:natraj.gudla@ge.com] 
Sent: Thursday, November 01, 2007 9:40 AM
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

 

This is also possible. All that you require is to build an XMLStreamReader and pass it to the parse method from the factory of your top level class. Check my sample code below. I created a stream reader from a sample xml file, in your case you can figure out to pass a string having the xml. Loan request is a binding class.

 

DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

InputSource inputSource = new InputSource("xmldata/LnRq_Accept.xml"); 

Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);

StringWriter sw = new StringWriter();

Transformer serializer = TransformerFactory.newInstance().newTransformer();

serializer.transform(new DOMSource(document), new StreamResult(sw));

XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(sw.toString().getBytes()));

LoanRequest lnReq = LoanRequest.Factory.parse(reader);

-----Original Message-----
From: Sudhir Sharma [mailto:sudhir.sharma.tr@espireinfo.com]
Sent: 01 November 2007 04:34
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

Hi,

 

I am also facing the same problem. Can anyone help us out.

Any help will be appreciated. 

 

Thanks & Best Regards,

Sudhir Sharma


  _____  


From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com] 
Sent: Wednesday, October 31, 2007 4:43 PM
To: axis-user@ws.apache.org
Subject: Serialize/Deserialize

 

Axis allows you to serialize an object into XML using a SerializationContext.  For example,

 

   // serialize the object

  StringWriter strWriter = new StringWriter();

  SerializationContext ctx = new SerializationContext(strWriter, MessageContext.getCurrentContext());

  ctx.serialize(new QName("MyObjectNamespace",  "MyObject"), null, myObject, null, Boolean.FALSE, Boolean.FALSE);

  String value = strWriter.toString();

 

Is it possible to use Axis to deserialize this string back into an object of type MyObject?  If so, can you please provide an example?

 

Regards,
Richard

 

-----------------------------------------------------------------------------------------------------------
This message is intended for the addressee or its representative only. Any form of unauthorized use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail message and its contents, please notify the sender immediately and delete this message and all its attachments subsequently.


RE: Serialize/Deserialize

Posted by ABBUHL Richard NL <Ri...@atradius.com>.
Thanks for the reply.  On the last line you indicated that LoanRequest
is a binding class.  The class which I need to parse was generated by
Axis and it only implements Serializable so there is no Factory.parse
method available.  Any suggestions?

 

________________________________

From: Gudla, Natraj (GE Money, consultant) [mailto:natraj.gudla@ge.com] 
Sent: Thursday, November 01, 2007 9:40 AM
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize

 

This is also possible. All that you require is to build an
XMLStreamReader and pass it to the parse method from the factory of your
top level class. Check my sample code below. I created a stream reader
from a sample xml file, in your case you can figure out to pass a string
having the xml. Loan request is a binding class.

 

DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();

InputSource inputSource = new InputSource("xmldata/LnRq_Accept.xml"); 

Document document =
documentBuilderFactory.newDocumentBuilder().parse(inputSource);

StringWriter sw = new StringWriter();

Transformer serializer =
TransformerFactory.newInstance().newTransformer();

serializer.transform(new DOMSource(document), new StreamResult(sw));

XMLStreamReader reader =
XMLInputFactory.newInstance().createXMLStreamReader(new
ByteArrayInputStream(sw.toString().getBytes()));

LoanRequest lnReq = LoanRequest.Factory.parse(reader);

	-----Original Message-----
	From: Sudhir Sharma [mailto:sudhir.sharma.tr@espireinfo.com]
	Sent: 01 November 2007 04:34
	To: axis-user@ws.apache.org
	Subject: RE: Serialize/Deserialize

	Hi,

	 

	I am also facing the same problem. Can anyone help us out.

	Any help will be appreciated. 

	 

	Thanks & Best Regards,

	Sudhir Sharma

	
________________________________


	From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com] 
	Sent: Wednesday, October 31, 2007 4:43 PM
	To: axis-user@ws.apache.org
	Subject: Serialize/Deserialize

	 

	Axis allows you to serialize an object into XML using a
SerializationContext.  For example,

	 

	   // serialize the object

	  StringWriter strWriter = new StringWriter();

	  SerializationContext ctx = new SerializationContext(strWriter,
MessageContext.getCurrentContext());

	  ctx.serialize(new QName("MyObjectNamespace",  "MyObject"),
null, myObject, null, Boolean.FALSE, Boolean.FALSE);

	  String value = strWriter.toString();

	 

	Is it possible to use Axis to deserialize this string back into
an object of type MyObject?  If so, can you please provide an example?

	 

	Regards,
	Richard

	 

	
------------------------------------------------------------------------
-----------------------------------
	This message is intended for the addressee or its representative
only. Any form of unauthorized use, publication, reproduction, copying
or disclosure of the content of this e-mail is not permitted. If you are
not the intended recipient of this e-mail message and its contents,
please notify the sender immediately and delete this message and all its
attachments subsequently.


RE: Serialize/Deserialize

Posted by "Gudla, Natraj (GE Money, consultant)" <na...@ge.com>.
This is also possible. All that you require is to build an XMLStreamReader and pass it to the parse method from the factory of your top level class. Check my sample code below. I created a stream reader from a sample xml file, in your case you can figure out to pass a string having the xml. Loan request is a binding class.
 
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

InputSource inputSource = new InputSource("xmldata/LnRq_Accept.xml"); 

Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);

StringWriter sw = new StringWriter();

Transformer serializer = TransformerFactory.newInstance().newTransformer();

serializer.transform(new DOMSource(document), new StreamResult(sw));

XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new ByteArrayInputStream(sw.toString().getBytes()));

LoanRequest lnReq = LoanRequest.Factory.parse(reader);

-----Original Message-----
From: Sudhir Sharma [mailto:sudhir.sharma.tr@espireinfo.com]
Sent: 01 November 2007 04:34
To: axis-user@ws.apache.org
Subject: RE: Serialize/Deserialize



Hi,

 

I am also facing the same problem. Can anyone help us out.

Any help will be appreciated. 

 

Thanks & Best Regards,

Sudhir Sharma


  _____  


From: ABBUHL Richard NL [mailto:Richard.ABBUHL@atradius.com] 
Sent: Wednesday, October 31, 2007 4:43 PM
To: axis-user@ws.apache.org
Subject: Serialize/Deserialize

 

Axis allows you to serialize an object into XML using a SerializationContext.  For example,

 

   // serialize the object

  StringWriter strWriter = new StringWriter();

  SerializationContext ctx = new SerializationContext(strWriter, MessageContext.getCurrentContext());

  ctx.serialize(new QName("MyObjectNamespace",  "MyObject"), null, myObject, null, Boolean.FALSE, Boolean.FALSE);

  String value = strWriter.toString();

 

Is it possible to use Axis to deserialize this string back into an object of type MyObject?  If so, can you please provide an example?

 

Regards,
Richard

 

-----------------------------------------------------------------------------------------------------------
This message is intended for the addressee or its representative only. Any form of unauthorized use, publication, reproduction, copying or disclosure of the content of this e-mail is not permitted. If you are not the intended recipient of this e-mail message and its contents, please notify the sender immediately and delete this message and all its attachments subsequently.