config.setProperty("number", new Integer(65535));
config.getByte("number");this one will fail and throw an exception:
config.setProperty("number", "65535");
config.getByte("number");I see 2 solutions to solve this, we can either:
- serialize the Number to a String on calling setProperty, then it will be automatically parsed. I'm a bit reluctant to change the object stored though, and this will not work if the object is already stored as a Number (if we read a JNDIConfiguration for example). The serialization could also occur in the getXXX method, something like this:
if (value instanceof Number) {
String s = value.toString();
return new Byte(s);
}- downcast the number stored as a string by creating a BigDecimal and calling Number.xxxValue() instead of parsing the String through the concrete Number class. For example :
BigDecimal number = new BigDecimal((String) value);
return new Byte(number.byteValue());instead of
Byte b = new Byte((String) value);
return b;Alternatively we could also detect the loss of information and log a warning.
Emmanuel Bourg
Eric Pugh wrote:
Re: [configuration] Numbers conversionsOh... Ick... I guess that while that is consistent with downcasting in Java, I don't think that it is consistent with how the Commons Configuration API "feels".. The api does a lot to try and convert things for the user..
Do you have a real resistence to the idea of throwing an exception? If you like, apply your changes, and then I'll do it.. It just seems to make more sense...
Eric
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
