Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

XMLEncoder problem

Thread view: 
Tomba - 11 Jan 2006 21:20 GMT
Hi,

I hope anyone here has used XMLEncoder sometime. Well I want to write an
 object to an XML file with the encoder.

The object is in fact a bean but with several setter and getter methods
defined in superclasses. I have done introspection and it shows all the
properties nicely.

However, I am under the impression that XMLEncoder only writes out the
bean properties with getter and setter methods defined in the class
itself, and not in superclasses.

Is my assumption right? And if so, is there any solution to this
problem, because it's useless to me this way :((

Thanks a lot,
Steven
Chris Riesbeck - 12 Jan 2006 18:37 GMT
> Hi,
>
[quoted text clipped - 11 lines]
> Is my assumption right? And if so, is there any solution to this
> problem, because it's useless to me this way :((

Why assume when you can write code and test? Make 3 files and run
XMLTester. What do you see being printed?

import java.beans.XMLEncoder;
import java.io.*;

public class XMLTester {

  public static void main(String[] args) {
    XMLEncoder e = new XMLEncoder(System.out);
    e.writeObject(new Baz(300, 400));
    e.close();
  }
}

public class Foo {
  private int n = 100;
  public int getFooValue() { return n; }
  public void setFooValue(int i) { n = i; }
}

public class Baz extends Foo {
  private int n = 200;
  public Baz() {};
  public Baz(int i, int j) { n = i; setFooValue(j); }
  public int getBazValue() { return n; }
  public void setBazValue(int i) { n = i; }
}


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.