Doubt in XMLDecoder??
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sangram_2222_kumar
Posted On:   Thursday, July 22, 2004 11:32 PM

Hi, while executing the below program: //========== Program starts ===============> import java.beans.Encoder; import java.beans.Expression; import java.beans.PersistenceDelegate; import java.beans.XMLDecoder; import java.beans.XMLEncoder; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; public class SerializationTest { public SerializationTest() { super(); // TODO Auto-generated constructor stub } public static void main(String[] args) { try{ XMLEncoder e = new XMLEncoder( new BufferedOutputStream(    More>>

Hi,


while executing the below program:


			

//========== Program starts ===============>
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class SerializationTest {

public SerializationTest() {
super();
// TODO Auto-generated constructor stub
}

public static void main(String[] args) {
try{
XMLEncoder e = new XMLEncoder(
new BufferedOutputStream(
new FileOutputStream("D://Temp//Test.xml")));

e.setPersistenceDelegate(Integer.class,
new PersistenceDelegate() {
protected Expression instantiate(Object oldInstance,Encoder out) {
return new Expression((Integer)oldInstance,
((Integer)oldInstance).getClass(),
"getInteger",
new Object[]{ ((Integer)oldInstance).toString() });
}
});

e.writeObject(new Integer(1222));
e.close();

XMLDecoder d2 = new XMLDecoder(new FileInputStream("D://Temp//Test.xml"));
Object i = d2.readObject();
System.out.println(i.getClass());
System.out.println(((Integer)i).intValue());
}
catch(Exception e){
//
}
}
}

//===========Program ends =====================>

I am getting the output as:


//============ Output stream start ========>

<?xml version="1.0" encoding="UTF-8"?>

1222


//============ Output stream end ========>





The question is:


I am encoding an Integer class by constructing a custom PersistenceDelegate, which produces the ouput without any tag above (parent of) tag.





Which logic XMLDecoder uses to know at runtime the Classtype of the Serialized data (as in this case above), if the tag is absent in serialized data??


regds

   <<Less
About | Sitemap | Contact