@Test(expected = IllegalArgumentException.class) public void convertedClassesMustHaveNoArgsConstructor() { new MapToObjectReflectionConverter<>(ClassWithoutNoArgsConstructor.class).convert(source); }
@Override public T convert(final Map<String, String> source) { try { final T mappedType = type.newInstance(); for (final Entry<String, String> entry : source.entrySet()) { try { final Field fieldName = type.getDeclaredField(entry.getKey()); fieldName.setAccessible(true); fieldName.set(mappedType, entry.getValue()); } catch (final NoSuchFieldException e) { } catch (final SecurityException e) { throw new AssertionError("Failed to populate type: " + type, e); } } return mappedType; } catch (final InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(type.getClass().getName() + " should have a public no-arguments constructor.", e); } }
MapToObjectReflectionConverter implements Converter<Map<String, String>, T> { @Override public T convert(final Map<String, String> source) { try { final T mappedType = type.newInstance(); for (final Entry<String, String> entry : source.entrySet()) { try { final Field fieldName = type.getDeclaredField(entry.getKey()); fieldName.setAccessible(true); fieldName.set(mappedType, entry.getValue()); } catch (final NoSuchFieldException e) { } catch (final SecurityException e) { throw new AssertionError("Failed to populate type: " + type, e); } } return mappedType; } catch (final InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(type.getClass().getName() + " should have a public no-arguments constructor.", e); } } }
MapToObjectReflectionConverter implements Converter<Map<String, String>, T> { @Override public T convert(final Map<String, String> source) { try { final T mappedType = type.newInstance(); for (final Entry<String, String> entry : source.entrySet()) { try { final Field fieldName = type.getDeclaredField(entry.getKey()); fieldName.setAccessible(true); fieldName.set(mappedType, entry.getValue()); } catch (final NoSuchFieldException e) { } catch (final SecurityException e) { throw new AssertionError("Failed to populate type: " + type, e); } } return mappedType; } catch (final InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(type.getClass().getName() + " should have a public no-arguments constructor.", e); } } MapToObjectReflectionConverter(final Class<T> type); }
MapToObjectReflectionConverter implements Converter<Map<String, String>, T> { @Override public T convert(final Map<String, String> source) { try { final T mappedType = type.newInstance(); for (final Entry<String, String> entry : source.entrySet()) { try { final Field fieldName = type.getDeclaredField(entry.getKey()); fieldName.setAccessible(true); fieldName.set(mappedType, entry.getValue()); } catch (final NoSuchFieldException e) { } catch (final SecurityException e) { throw new AssertionError("Failed to populate type: " + type, e); } } return mappedType; } catch (final InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(type.getClass().getName() + " should have a public no-arguments constructor.", e); } } MapToObjectReflectionConverter(final Class<T> type); @Override T convert(final Map<String, String> source); }
MapToObjectReflectionConverter implements Converter<Map<String, String>, T> { @Override public T convert(final Map<String, String> source) { try { final T mappedType = type.newInstance(); for (final Entry<String, String> entry : source.entrySet()) { try { final Field fieldName = type.getDeclaredField(entry.getKey()); fieldName.setAccessible(true); fieldName.set(mappedType, entry.getValue()); } catch (final NoSuchFieldException e) { } catch (final SecurityException e) { throw new AssertionError("Failed to populate type: " + type, e); } } return mappedType; } catch (final InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(type.getClass().getName() + " should have a public no-arguments constructor.", e); } } MapToObjectReflectionConverter(final Class<T> type); @Override T convert(final Map<String, String> source);  }