LocaleMapper extends Mapper<Locale> { @Nullable @Override public Locale fromDb(@Nullable final Object dbValue) throws MapperException { if (dbValue == null) { return null; } if (dbValue instanceof String) { try { return LocaleUtil.parse((String) dbValue); } catch (final IllegalArgumentException e) { throw new MapperException("Invalid Locale value '" + dbValue + "'. " + e.getMessage()); } } throw new MapperException("String value expected, " + "got a value of type: " + dbValue.getClass().getCanonicalName()); }  @Nullable @Override Locale fromDb(@Nullable final Object dbValue); @Nullable @Override Object toDb(@Nullable final Locale value);  }
@Test public void testFromDb() throws MapperException { LOG.info("testFromDb"); Assert.assertEquals(Locale.ENGLISH, mapper.fromDb("en")); Assert.assertEquals(Locale.US, mapper.fromDb("en_US")); Assert.assertEquals(new Locale("nl", "NL"), mapper.fromDb("nl_NL")); Assert.assertEquals(new Locale("en", "NL"), mapper.fromDb("en_NL")); Assert.assertEquals(new Locale("en", "NL"), mapper.fromDb("en_NL")); Assert.assertEquals(new Locale("es", "ES", "Traditional_WIN"), mapper.fromDb("es_ES_Traditional_WIN")); }