DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16525>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=16525

BeanUtils.setProperty is over-zealous at converting types

           Summary: BeanUtils.setProperty is over-zealous at converting
                    types
           Product: Commons
           Version: 1.6 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Blocker
          Priority: Other
         Component: Bean Utilities
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


As of Release 1.6, BeanUtils.setProperty goes to great lengths to convert types
into Strings and then from Strings into valid target types, without ever
considering whether the original value was valid to start with.

e.g: 
setProperty( bean, "object", new Integer(77) ) ;
will set the "object" in the bean to the String "77".
when what is intended is to set it to an Integer.

copyProperty gets it right, but it doesn't understand nested properties, so it
isn't useful for my situation.

PropertyUtils does a better job, but it doesn't do *any* conversions, so it
breaks in other situations.

There doesn't seem to be a reasonable way to say:
 "set nested/indexed/mapped property 'X' in this bean to be value 'Y', and do
whatever conversions are necessary to get it there"

The options seem to be:
"set simple property X to value Y with proper conversions" (BeanUtils.copyProperty)
"set complex property X to value Y with too many conversions"
(BeanUtils.setProperty)
"set complex property X to value Y with no conversions" (PropertyUtils.setProperty)

Is BeanUtils.setProperty wrong? Or do we need another method that set complex
properties using the same conversion methds as "copyProperty" ?

I have a patch (which I'll attach) which makes setProperty do something closer
to what I think it should do, but I'm not sure if that's the correct approach.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to