XMLEncoder does not recognize bean property

P

Paul Kaiser

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
 
C

Chris Riesbeck

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top