Advertisement

07.11.2008 at 01:17AM PDT, ID: 23556474
[x]
Attachment Details

Disadvantages of XMLEncoder & XMLDecoder?

Asked by josecuadra in Java Programming Language, J2EE, Java Servlets

Tags: Java

Hello Experts,

Please advice me on this one. I have a fairly big object that is populated on the client side, with input from a <form>. We want to transmit it over the network to be received by the server (the form has around 80 fields or more). Our current approach is using the XMLEncoder, to convert the object to XML and sending it over the network. On the server end we use the XMLDecoder to do the conversion back to the object again, and save it to the DB and stuff...

The information being transmitted is kind of critical so I wanted to know if there are any known bad issues concerning this type of transformation concerning this two classes? Maybe data gets corrupted or somethings? Please advice...

(Just for your information: The data is being sent via a Post request)

And also, is there a way to get kind of a checksum of the object being transmitted to be able to check it back on the server to verify integrity? (maybe this could deserve another question)

Attached is the code from our current approach.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
//obtaining the XML for transmission
	public static String toXML(Object bean) {
 
		String XMLBean = "";
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
		// Create XML encoder.
		XMLEncoder xenc = new XMLEncoder(baos);
 
		xenc.writeObject(bean);
		xenc.flush();
		xenc.close();
		XMLBean = baos.toString();
		return XMLBean;
	}
 
//obtaining object from XML
	public static Object fromXML(String XMLBean) {
		byte[] buffer = XMLBean.getBytes();
		ByteArrayInputStream bais = new ByteArrayInputStream(buffer);
 
		// Create XML decoder.
		XMLDecoder xdec = new XMLDecoder(bais);
 
		// Read object.
		return xdec.readObject();
	}
[+][-]07.11.2008 at 02:08AM PDT, ID: 21980890

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Java Programming Language, J2EE, Java Servlets
Tags: Java
Sign Up Now!
Solution Provided By: objects
Participating Experts: 2
Solution Grade: A
 
 
[+][-]07.11.2008 at 02:18AM PDT, ID: 21980920

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]07.13.2008 at 05:27PM PDT, ID: 21994914

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 06:59PM PDT, ID: 21995166

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 07:00PM PDT, ID: 21995171

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.13.2008 at 09:45PM PDT, ID: 21995693

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628