@Test public void testRetrieveObjectType() { final UserCriteria user = new UserCriteria(); final UserCredential cred = new UserCredential(); user.setFirstName("Test"); user.setEmailAddress("admin@ideyatech.com"); cred.setUsername("testname"); cred.setPassword("password"); cred.setId(123l); cred.setEnabled(true); user.setCredential(cred); Assert.assertEquals(String.class, CrudUtil.retrieveObjectType(user, "firstName")); Assert.assertEquals(String.class, CrudUtil.retrieveObjectType(user, "credential.username")); Assert.assertEquals(Long.class, CrudUtil.retrieveObjectType(user, "credential.id")); try { Assert.assertEquals(null,CrudUtil.retrieveObjectType(user, "garbage")); Assert.fail("No exception thrown on invalid property [garbage]"); } catch (final InvalidImplementationException iie) { } try { Assert.assertEquals(null,CrudUtil.retrieveObjectType(user, "credential.garbage")); Assert.fail("No exception thrown on invalid property [credential.garbage]"); } catch (final InvalidImplementationException iie) { } }
public static Class<?> retrieveObjectType(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); final Object ivalue = method.invoke(obj); return retrieveObjectType(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); return method.getReturnType(); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } }
CrudUtil { public static Class<?> retrieveObjectType(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); final Object ivalue = method.invoke(obj); return retrieveObjectType(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); return method.getReturnType(); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } }
CrudUtil { public static Class<?> retrieveObjectType(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); final Object ivalue = method.invoke(obj); return retrieveObjectType(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); return method.getReturnType(); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); }
CrudUtil { public static Class<?> retrieveObjectType(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); final Object ivalue = method.invoke(obj); return retrieveObjectType(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); return method.getReturnType(); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); static String buildCreateMessage(final BaseEntity obj); static List<String> getUpdatedFields(final BaseEntity oldObject,
			final BaseEntity newObject); static String convertAuditableFieldsToJson(BaseEntity obj); @SuppressWarnings({ "rawtypes", "unchecked" }) static String buildUpdateMessage(final BaseEntity oldObject,
			final BaseEntity newObject); static String buildDeleteMessage(final BaseEntity obj); static Map<String, Object> buildMapValues(final BaseEntity object); @SuppressWarnings("rawtypes") static Map<String, Object> buildMapValues(final BaseEntity object,
			final List<String> fields); static String buildURLParameters(final BaseEntity object); @SuppressWarnings("rawtypes") static String buildJpaQueryString(final BaseEntity example,
			final boolean exactMatch); @SuppressWarnings("rawtypes") static Object retrieveObjectValue(final Object obj,
			final String property); static Object retrieveNullableObjectValue(final Object obj,
			final String property); static Class<?> retrieveObjectType(final Object obj,
			final String property); static Boolean evaluateExpression(final Object obj,
			final String expression); @SuppressWarnings("unchecked") static String replaceSQLParameters(String sql, final Object obj); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz,
			final boolean includeParent); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz,
			final boolean includeParent); static List<MessageResponse> convertErrorMessage(
			final BindingResult bindingResult, final Locale locale,
			final MessageSource messageSource); static List<MessageResponse> buildSuccessMessage(
			final BaseEntity object, final String code, final Locale locale,
			final MessageSource messageSource); static boolean isCollection(final Object ob); static BaseEntity clone(final BaseEntity source); }
CrudUtil { public static Class<?> retrieveObjectType(final Object obj, final String property) { if (property.contains(".")) { final String props[] = property.split("\\."); try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(props[0])); final Object ivalue = method.invoke(obj); return retrieveObjectType(ivalue, property.substring(props[0].length() + 1)); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } else { try { final Method method = obj.getClass().getMethod( NamingUtil.toGetterName(property)); return method.getReturnType(); } catch (final Exception e) { throw new InvalidImplementationException( "Failed to retrieve value for " + property, e); } } } private  CrudUtil(); static String buildCreateMessage(final BaseEntity obj); static List<String> getUpdatedFields(final BaseEntity oldObject,
			final BaseEntity newObject); static String convertAuditableFieldsToJson(BaseEntity obj); @SuppressWarnings({ "rawtypes", "unchecked" }) static String buildUpdateMessage(final BaseEntity oldObject,
			final BaseEntity newObject); static String buildDeleteMessage(final BaseEntity obj); static Map<String, Object> buildMapValues(final BaseEntity object); @SuppressWarnings("rawtypes") static Map<String, Object> buildMapValues(final BaseEntity object,
			final List<String> fields); static String buildURLParameters(final BaseEntity object); @SuppressWarnings("rawtypes") static String buildJpaQueryString(final BaseEntity example,
			final boolean exactMatch); @SuppressWarnings("rawtypes") static Object retrieveObjectValue(final Object obj,
			final String property); static Object retrieveNullableObjectValue(final Object obj,
			final String property); static Class<?> retrieveObjectType(final Object obj,
			final String property); static Boolean evaluateExpression(final Object obj,
			final String expression); @SuppressWarnings("unchecked") static String replaceSQLParameters(String sql, final Object obj); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Field> getAllFields(final Class clazz,
			final boolean includeParent); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz); @SuppressWarnings({ "rawtypes" }) static List<Method> getAllMethods(final Class clazz,
			final boolean includeParent); static List<MessageResponse> convertErrorMessage(
			final BindingResult bindingResult, final Locale locale,
			final MessageSource messageSource); static List<MessageResponse> buildSuccessMessage(
			final BaseEntity object, final String code, final Locale locale,
			final MessageSource messageSource); static boolean isCollection(final Object ob); static BaseEntity clone(final BaseEntity source);  }