1.4 beans.XMLEncoder/Decoder & StringBuffers
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   J_Greene
Posted On:   Wednesday, June 19, 2002 09:31 AM

Hi... I've just started playing with the java.beans.XMLEncoder/Decoder in the JDK 1.4 . I have an object that has a StringBuffer as an attribute. Everything else is writting - but that is not. I get the StringBuffer definition - but not the value in the string buffer. Pretty sure it is something simple that I'm doing wrong. Below is my sample code. Can someone give me a clue as to what I've missed? Thanks import java.io.*; import java.beans.XMLEncoder; import java.beans.XMLDecoder; import javax.swing.*; public class h {    int _one = 0;       More>>

Hi... I've just started playing with the java.beans.XMLEncoder/Decoder in the
JDK 1.4 . I have an object that has a StringBuffer as an attribute.
Everything else is writting - but that is not. I get the StringBuffer
definition - but not the value in the string buffer.


Pretty sure it is something simple that I'm doing wrong.
Below is my sample code. Can someone give me a clue as to what I've missed?


Thanks



			

import java.io.*;

import java.beans.XMLEncoder;

import java.beans.XMLDecoder;

import javax.swing.*;

public class h {

   int _one = 0;

   String _hi = null;

   StringBuffer _hello = null;

   public h() {

   }

   public h(int one, String hi, StringBuffer hello) {

        setOne(one);

        setHi(hi);

        setHello(hello);

   }

   public int getOne() { return _one; } ;

   public void setOne(int o) { _one = o; } ;

   public String getHi() { return _hi; } ;

   public void setHi(String s) { _hi = s; } ;

   public StringBuffer getHello() { return _hello; } ;

   public void setHello(StringBuffer s) { _hello = s; } ;

   public static void main(String[] f) {

        h tempObj = new h(1, "hi",new StringBuffer("Hello"));

        try {

         XMLEncoder e = new XMLEncoder(

         new BufferedOutputStream(

         new FileOutputStream("h.xml")));

         e.writeObject(tempObj);

         e.close();

        } catch (Throwable t) {

        t.printStackTrace();

        }

   }

}

   <<Less

Re: 1.4 beans.XMLEncoder/Decoder & StringBuffers

Posted By:   Roseanne_Zhang  
Posted On:   Tuesday, September 3, 2002 07:41 PM

Ignore my post, I was wrong, and I had mixed with a different scenario. Sorry!

Re: 1.4 beans.XMLEncoder/Decoder & StringBuffers

Posted By:   Roseanne_Zhang  
Posted On:   Tuesday, September 3, 2002 07:16 PM

Simple, since StringBuffer does not override the toString() method of Object. What you got is the default behavior of the toString() method. Surprised? I was surprised too quite a while ago in a different scenario...
About | Sitemap | Contact