[morph-developer] Changing Morph so it does NOT pick up on Locale
Brought to you by:
orangeherbert,
sgarlatm
From: Matt S. <mat...@sp...> - 2009-10-16 17:27:10
|
Hey Matt B, It sure has been a while! I hope you are doing well. Today I had a French user of our application unable to use the application because Morph was unable to convert the String "3.33" to a Double. The reason was that Morph was trying to perform the conversion using French as the locale instead of English. This happens because currently Transfers extending from BaseTransformer are too smart when it comes to determining the Locale to use for performing conversions. For calls when the Locale is not specified when calling convert or copy, instead of simply using Locale.getDefault(), Morph's trying to find the Locale from Spring. This leads to unexpected behavior because methods like Integer.parseInt work when Morph doesn't. This has actually come up several times for us at Spider, so I am going to change BaseTransformer.getLocale() as follows. Here is the old version protected Locale getLocale() { Locale locale = null; if (ClassUtils.isClassPresent(SPRING_LOCALE_CONTEXT_HOLDER_CLASS)) { try { Class contextHolderClass = Class.forName(SPRING_LOCALE_CONTEXT_HOLDER_CLASS); Method getLocaleMethod = contextHolderClass.getMethod("getLocale", (Class[]) null); locale = (Locale) getLocaleMethod.invoke(null, (Object[]) null); } catch (Exception e) { log.warn("Unable to retrieve locale from Spring", e); } } if (locale == null) { locale = Locale.getDefault(); } return locale; } New version: protected Locale getLocale() { return Locale.getDefault(); } Sound good? Thanks! Matt -- This message is intended only for the named recipient. If you are not the intended recipient, you are notified that disclosing, copying, distributing, or taking any action in reliance on the contents of this information is strictly prohibited. |