Author: doogie Date: Fri Jun 28 19:08:16 2013 New Revision: 1497890 URL: http://svn.apache.org/r1497890 Log: FIX: java.sql.Timestamp extends java.util.Date, and both have converters registered. In some cases, however, the Date convertor would be used instead of the more correct Timestamp convertor. This fix implements a most-specific type algorithm to find the better convertor.
Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java?rev=1497890&r1=1497889&r2=1497890&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/conversion/Converters.java Fri Jun 28 19:08:16 2013 @@ -85,12 +85,24 @@ OUTER: if (noConversions.contains(key)) { throw new ClassNotFoundException("No converter found for " + key); } + Class foundSourceClass = null; + Converter<?, ?> foundConverter = null; for (Converter<?, ?> value : converterMap.values()) { if (value.canConvert(sourceClass, targetClass)) { - converterMap.putIfAbsent(key, value); - continue OUTER; + // this converter can deal with the source/target pair + if (foundSourceClass == null || foundSourceClass.isAssignableFrom(value.getSourceClass())) { + // remember the current target source class; if we find another converter, check + // to see if it's source class is assignable to this one, and if so, it means it's + // a child class, so we'll then take that converter. + foundSourceClass = value.getSourceClass(); + foundConverter = value; + } } } + if (foundConverter != null) { + converterMap.putIfAbsent(key, foundConverter); + continue OUTER; + } for (ConverterCreator value : creators) { result = createConverter(value, sourceClass, targetClass); if (result != null) {