XMLEncoder does not recognize bean property

Discussion in 'Java' started by Paul Kaiser, May 21, 2004.

  1. Paul Kaiser

    Paul Kaiser Guest

    I experienced some weirdness and want to find out if it is me or
    XMLEncoder.

    I have a class, Administrator, that has several properties; one of
    them being isid, which is a String. The getter/setters are:

    private String isid;
    public String getIsid() { return (this.isid); }
    public void setIsid(String isid) { this.isid = isid; }

    The Administrator objects were getting encoded and decoded just fine.
    When I wanted to force the value of isid to all upper case, I changed
    the getter/setter to:

    private String isid;
    public String getIsid() { return (this.isid.toUpperCase()); }
    public void setIsid(String isid) { this.isid = isid.toUpperCase(); }

    With this change, XMLEncoder stopped encoding the isid property
    altogether. After a bit of gnashing, I reverted the getter/setter to
    the original and it worked just fine. I don't understand why the
    method implementation would cause a change in what XMLEncoder
    considers a public property. I thought it would simply look for things
    that have public get<VariableName>() and set<VariableName>() methods.

    Does anyone have any thoughts?

    Thanks,
    Paul
    Paul Kaiser, May 21, 2004
    #1
    1. Advertising

  2. In article <>,
    (Paul Kaiser) wrote:

    > I experienced some weirdness and want to find out if it is me or
    > XMLEncoder.
    >
    > I have a class, Administrator, that has several properties; one of
    > them being isid, which is a String. The getter/setters are:
    >
    > private String isid;
    > public String getIsid() { return (this.isid); }
    > public void setIsid(String isid) { this.isid = isid; }
    >
    > The Administrator objects were getting encoded and decoded just fine.
    > When I wanted to force the value of isid to all upper case, I changed
    > the getter/setter to:
    >
    > private String isid;
    > public String getIsid() { return (this.isid.toUpperCase()); }
    > public void setIsid(String isid) { this.isid = isid.toUpperCase(); }
    >
    > With this change, XMLEncoder stopped encoding the isid property
    > altogether.


    How did you avoid a NullPointerException? XMLEncoder creates
    an empty bean first, then compares your bean with the empty
    bean to see which properties actually need to be written.
    Your getIsid() blows up on the empty bean.
    Chris Riesbeck, May 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Benjamin Stewart

    To bean or not to bean...

    Benjamin Stewart, Jun 30, 2003, in forum: Java
    Replies:
    0
    Views:
    789
    Benjamin Stewart
    Jun 30, 2003
  2. milkyway
    Replies:
    2
    Views:
    618
    Ryan Stewart
    Dec 26, 2004
  3. jill
    Replies:
    5
    Views:
    15,537
  4. Steven T. Hatton

    To bean or not to bean

    Steven T. Hatton, Aug 28, 2004, in forum: C++
    Replies:
    61
    Views:
    1,320
    Steven T. Hatton
    Sep 10, 2004
  5. Replies:
    3
    Views:
    713
    Chris Riesbeck
    Jun 23, 2006
Loading...

Share This Page