Re: Re: [beanutils] BeanUtilsBean#setProperty() behaviour in 1.7 and 1.8
Wed, 09 Mar 2011 15:38:23 -0800 2011/3/7 Björn Moritz bjoern.mor...@gmail.com: Hello, is there a reason for BeanUtilsBean#setProperty() in line 968 not using the PropertyType of the current PropertyDescriptor as the type of class to convert to, but instead the class of the value to be converted? Until beanutils 1.7 a String array was converted to a string using the first element of the array; since 1.8 the string array is converted to a string using the toString method of the array (as the destination type is now an array type). Why can't we use the property descriptor for these mapped properties, too? BeanUtils (uniquely) has the concept of a MappedPropertyDescriptor like the IndexedPropertyDescriptor, so that if you have acessor methods in your bean with a key parameter, then it assumes it is accessing an underlying Map. In that scenario it does indeed use the descriptor to determine the type. However if it has a Map property (i.e. has methods that set/return a Map) then there is no way to determine the type. By the time it reaches the line number you quote, then its in the later scenario and the type can't be determined - since the descriptor type should be a Map. Niall Hi Niall, thank you for your answer. So you're suggesting to replace in our beans code like this: public SortedMapString, String getWidth() { return widthMap; } public void setWidth(SortedMapString, String widthMap) { this.widthMap= widthMap; } with: public String getWidth(String index) { return widthMap.get(index); } public void setWidth(String index, String width) { widthMap.put(index, width); } Then BeanUtils will use a MappedPropertyDescriptor and map our values correctly? Björn Regards, Björn - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: Re: [beanutils] BeanUtilsBean#setProperty() behaviour in 1.7 and 1.8
2011/3/11 Björn Moritz bjoern.mor...@gmail.com: Wed, 09 Mar 2011 15:38:23 -0800 2011/3/7 Björn Moritz bjoern.mor...@gmail.com: Hello, is there a reason for BeanUtilsBean#setProperty() in line 968 not using the PropertyType of the current PropertyDescriptor as the type of class to convert to, but instead the class of the value to be converted? Until beanutils 1.7 a String array was converted to a string using the first element of the array; since 1.8 the string array is converted to a string using the toString method of the array (as the destination type is now an array type). Why can't we use the property descriptor for these mapped properties, too? BeanUtils (uniquely) has the concept of a MappedPropertyDescriptor like the IndexedPropertyDescriptor, so that if you have acessor methods in your bean with a key parameter, then it assumes it is accessing an underlying Map. In that scenario it does indeed use the descriptor to determine the type. However if it has a Map property (i.e. has methods that set/return a Map) then there is no way to determine the type. By the time it reaches the line number you quote, then its in the later scenario and the type can't be determined - since the descriptor type should be a Map. Niall Hi Niall, thank you for your answer. So you're suggesting to replace in our beans code like this: public SortedMapString, String getWidth() { return widthMap; } public void setWidth(SortedMapString, String widthMap) { this.widthMap= widthMap; } with: public String getWidth(String index) { return widthMap.get(index); } public void setWidth(String index, String width) { widthMap.put(index, width); } Then BeanUtils will use a MappedPropertyDescriptor and map our values correctly? Yes, but I think you could add those methods (rather than replace) and it should work. Niall Björn Regards, Björn - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org
Re: [beanutils] BeanUtilsBean#setProperty() behaviour in 1.7 and 1.8
2011/3/7 Björn Moritz bjoern.mor...@gmail.com: Hello, is there a reason for BeanUtilsBean#setProperty() in line 968 not using the PropertyType of the current PropertyDescriptor as the type of class to convert to, but instead the class of the value to be converted? Until beanutils 1.7 a String array was converted to a string using the first element of the array; since 1.8 the string array is converted to a string using the toString method of the array (as the destination type is now an array type). Why can't we use the property descriptor for these mapped properties, too? BeanUtils (uniquely) has the concept of a MappedPropertyDescriptor like the IndexedPropertyDescriptor, so that if you have acessor methods in your bean with a key parameter, then it assumes it is accessing an underlying Map. In that scenario it does indeed use the descriptor to determine the type. However if it has a Map property (i.e. has methods that set/return a Map) then there is no way to determine the type. By the time it reaches the line number you quote, then its in the later scenario and the type can't be determined - since the descriptor type should be a Map. Niall Regards, Björn - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org - To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org