Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XMLEncoder does not recognize bean property

Reply
Thread Tools

XMLEncoder does not recognize bean property

 
 
Paul Kaiser
Guest
Posts: n/a
 
      05-21-2004
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
 
Reply With Quote
 
 
 
 
Chris Riesbeck
Guest
Posts: n/a
 
      05-24-2004
In article <(E-Mail Removed) >,
http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts - bean:write or html:text - not getting bean value - Please help jill Java 5 12-15-2005 03:03 PM
indexed property for array does not see my bean :-( milkyway Java 2 12-26-2004 03:04 PM
To bean or not to bean Steven T. Hatton C++ 61 09-10-2004 07:14 AM
Mr. Bean Complete Bean NOT complete!! Waterperson77 DVD Video 5 12-10-2003 05:22 PM
To bean or not to bean... Benjamin Stewart Java 0 06-30-2003 12:34 AM



Advertisments