@Test void testGetValuePropertyWithDotNotation() { assertThat(new ReflectionUtil().getValueFromObject(new DemoPojo(), "innerDemoPojo.cProperty", String.class)).isEqualTo("cPropertyByField"); assertThat(new ReflectionUtil().getValueFromObject(new DemoPojo(), "innerDemoPojo.dProperty", String.class)).isEqualTo("dPropertyByGetter"); assertThat(new ReflectionUtil().getValueFromObject(new DemoPojo(), "innerDemoPojo.innerInnerDemoPojo.eProperty", String.class)).isEqualTo("ePropertyByField"); assertThat(new ReflectionUtil().getValueFromObject(new DemoPojo(), "innerDemoPojo.innerInnerDemoPojo.fProperty", String.class)).isEqualTo("fPropertyByGetter"); }
public <T> T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass) { final int indexOfFirstDot = fieldName.indexOf(getAttributeSeparator()); if (indexOfFirstDot > 0) { final String firstFieldName = fieldName.substring(0, indexOfFirstDot); final String restOfFieldName = fieldName.substring(indexOfFirstDot + 1); final Object innerObject = getPlainValueFromObject(object, firstFieldName); return getValueFromObject(innerObject, restOfFieldName, valueClass); } return (T) getPlainValueFromObject(object, fieldName); }
ReflectionUtil { public <T> T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass) { final int indexOfFirstDot = fieldName.indexOf(getAttributeSeparator()); if (indexOfFirstDot > 0) { final String firstFieldName = fieldName.substring(0, indexOfFirstDot); final String restOfFieldName = fieldName.substring(indexOfFirstDot + 1); final Object innerObject = getPlainValueFromObject(object, firstFieldName); return getValueFromObject(innerObject, restOfFieldName, valueClass); } return (T) getPlainValueFromObject(object, fieldName); } }
ReflectionUtil { public <T> T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass) { final int indexOfFirstDot = fieldName.indexOf(getAttributeSeparator()); if (indexOfFirstDot > 0) { final String firstFieldName = fieldName.substring(0, indexOfFirstDot); final String restOfFieldName = fieldName.substring(indexOfFirstDot + 1); final Object innerObject = getPlainValueFromObject(object, firstFieldName); return getValueFromObject(innerObject, restOfFieldName, valueClass); } return (T) getPlainValueFromObject(object, fieldName); }  }
ReflectionUtil { public <T> T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass) { final int indexOfFirstDot = fieldName.indexOf(getAttributeSeparator()); if (indexOfFirstDot > 0) { final String firstFieldName = fieldName.substring(0, indexOfFirstDot); final String restOfFieldName = fieldName.substring(indexOfFirstDot + 1); final Object innerObject = getPlainValueFromObject(object, firstFieldName); return getValueFromObject(innerObject, restOfFieldName, valueClass); } return (T) getPlainValueFromObject(object, fieldName); }  String getStringValueFromObject(final Object object, final String fieldName); T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass); }
ReflectionUtil { public <T> T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass) { final int indexOfFirstDot = fieldName.indexOf(getAttributeSeparator()); if (indexOfFirstDot > 0) { final String firstFieldName = fieldName.substring(0, indexOfFirstDot); final String restOfFieldName = fieldName.substring(indexOfFirstDot + 1); final Object innerObject = getPlainValueFromObject(object, firstFieldName); return getValueFromObject(innerObject, restOfFieldName, valueClass); } return (T) getPlainValueFromObject(object, fieldName); }  String getStringValueFromObject(final Object object, final String fieldName); T getValueFromObject(final Object object, final String fieldName, final Class<T> valueClass); static final char ATTRIBUTE_SEPARATOR; }