class ObjectPropertyField {

  void applyValueParser(Object instance, String value) {
    try {
      field.set(instance, valueParser.apply(value));
    } catch (IllegalAccessException e) {
      throw ThrowableUtil.propagate(e);
    }
  }

}

class ObjectPropertyFieldTest {

  private static final String propName;

  @Test
  void testNonPrimitiveObjectPropertyField() throws Exception {

    NonPrimitiveClass instance = new NonPrimitiveClass();

    Class<NonPrimitiveClass> clazz = NonPrimitiveClass.class;
    ObjectPropertyField field_string =
        new ObjectPropertyField(clazz.getDeclaredField("str"), propName);
    ObjectPropertyField field_duration =
        new ObjectPropertyField(clazz.getDeclaredField("duration"), propName);

    field_string.applyValueParser(instance, "just str");
    field_duration.applyValueParser(instance, "100ms");

    assertEquals("just str", instance.str);
    assertEquals(Duration.ofMillis(100), instance.duration);
  }

}