@Test public void testConvert_Class() throws Exception { ClassConverter converter = new ClassConverter(); assertThat(BigDecimal.class).isEqualTo(converter.convert("java.math.BigDecimal", context)); }
@Override public Class<?> convert(String value, ConversionContext ctx) { if(value==null){ return null; } ctx.addSupportedFormats(getClass(),"<fullyQualifiedClassName>"); String trimmed = Objects.requireNonNull(value).trim(); try { return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader()); } catch(Exception e) { LOG.finest("Class not found in context CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassConverter.class.getClassLoader()); } catch(Exception e) { LOG.finest("Class not found in ClassConverter's CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader()); } catch(Exception e) { LOG.finest("Class not found in System CL (giving up): " + trimmed); return null; } }
ClassConverter implements PropertyConverter<Class<?>> { @Override public Class<?> convert(String value, ConversionContext ctx) { if(value==null){ return null; } ctx.addSupportedFormats(getClass(),"<fullyQualifiedClassName>"); String trimmed = Objects.requireNonNull(value).trim(); try { return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader()); } catch(Exception e) { LOG.finest("Class not found in context CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassConverter.class.getClassLoader()); } catch(Exception e) { LOG.finest("Class not found in ClassConverter's CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader()); } catch(Exception e) { LOG.finest("Class not found in System CL (giving up): " + trimmed); return null; } } }
ClassConverter implements PropertyConverter<Class<?>> { @Override public Class<?> convert(String value, ConversionContext ctx) { if(value==null){ return null; } ctx.addSupportedFormats(getClass(),"<fullyQualifiedClassName>"); String trimmed = Objects.requireNonNull(value).trim(); try { return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader()); } catch(Exception e) { LOG.finest("Class not found in context CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassConverter.class.getClassLoader()); } catch(Exception e) { LOG.finest("Class not found in ClassConverter's CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader()); } catch(Exception e) { LOG.finest("Class not found in System CL (giving up): " + trimmed); return null; } }  }
ClassConverter implements PropertyConverter<Class<?>> { @Override public Class<?> convert(String value, ConversionContext ctx) { if(value==null){ return null; } ctx.addSupportedFormats(getClass(),"<fullyQualifiedClassName>"); String trimmed = Objects.requireNonNull(value).trim(); try { return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader()); } catch(Exception e) { LOG.finest("Class not found in context CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassConverter.class.getClassLoader()); } catch(Exception e) { LOG.finest("Class not found in ClassConverter's CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader()); } catch(Exception e) { LOG.finest("Class not found in System CL (giving up): " + trimmed); return null; } }  @Override Class<?> convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode(); }
ClassConverter implements PropertyConverter<Class<?>> { @Override public Class<?> convert(String value, ConversionContext ctx) { if(value==null){ return null; } ctx.addSupportedFormats(getClass(),"<fullyQualifiedClassName>"); String trimmed = Objects.requireNonNull(value).trim(); try { return Class.forName(trimmed, false, Thread.currentThread().getContextClassLoader()); } catch(Exception e) { LOG.finest("Class not found in context CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassConverter.class.getClassLoader()); } catch(Exception e) { LOG.finest("Class not found in ClassConverter's CL: " + trimmed); } try { return Class.forName(trimmed, false, ClassLoader.getSystemClassLoader()); } catch(Exception e) { LOG.finest("Class not found in System CL (giving up): " + trimmed); return null; } }  @Override Class<?> convert(String value, ConversionContext ctx); @Override boolean equals(Object o); @Override int hashCode();  }