public <T> T to(Class<T> classOfT) { return to(classOfT, null); }
public Object objectFromString(String value, Class<?> objectClass) throws ParseException { if (value == null) { return null; } else if (objectClass.isAssignableFrom(value.getClass())) { return value; } // re-use the infinitely useful ParameterValue class ParameterValue pv = new ParameterValue(value); if (objectClass.isEnum()) { return pv.toEnum((Class) objectClass); } else if (java.sql.Date.class.isAssignableFrom(objectClass)) { return pv.toSqlDate(); } else if (java.sql.Time.class.isAssignableFrom(objectClass)) { return pv.toSqlTime(); } else if (java.sql.Timestamp.class.isAssignableFrom(objectClass)) { return pv.toSqlTimestamp(); } else if (Date.class.isAssignableFrom(objectClass)) { return pv.toDate(datePattern); } return pv.to(objectClass); }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Param annotation = parameter.getAnnotation(Param.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = routeContext.getParameter(name); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override public Object extract(Context context) { ParameterValue pv = context.getParameter(name); if (suffixes != null) { // automatically strip the suffix, if we can String value = pv.toString(); if (value != null) { String ext = Files.getFileExtension(value); if (!Strings.isNullOrEmpty(ext) && suffixes.contains(ext.toLowerCase())) { pv = new ParameterValue(Files.getNameWithoutExtension(value)); } } } if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
value = getParameters().get(parameterName).to(fieldClass, pattern);
@Override public Object extract(Context context) { ParameterValue pv = context.getParameter(name); if (suffixes != null) { // automatically strip the suffix, if we can String value = pv.toString(); if (value != null) { String ext = Files.getFileExtension(value); if (!Strings.isNullOrEmpty(ext) && suffixes.contains(ext.toLowerCase())) { pv = new ParameterValue(Files.getNameWithoutExtension(value)); } } } if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Header annotation = parameter.getAnnotation(Header.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = new ParameterValue(routeContext.getRequest().getLocale(), routeContext.getHeader(name)); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override public void setObjectType(Class<?> objectType) { ParameterValue testValue = new ParameterValue(); testValue.to(objectType); this.objectType = objectType; }
@Override public Object extract(Context context) { ParameterValue pv = new ParameterValue(context.getHeader(name)); if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override public void setObjectType(Class<?> objectType) { ParameterValue testValue = new ParameterValue(); testValue.to(objectType); this.objectType = objectType; }
@Override public Object extract(Context context) { ParameterValue pv = new ParameterValue(context.getHeader(name)); if (collectionType == null) { Object o = pv.to(objectType, pattern); return o; } Object o = pv.toCollection(collectionType, objectType, pattern); return o; } }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Param annotation = parameter.getAnnotation(Param.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = routeContext.getParameter(name); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }
@Override @SuppressWarnings("unchecked") public Object extract(MethodParameter parameter, RouteContext routeContext) { Header annotation = parameter.getAnnotation(Header.class); String name = getParameterName(parameter, annotation); String pattern = annotation.pattern(); ParameterValue parameterValue = new ParameterValue(routeContext.getRequest().getLocale(), routeContext.getHeader(name)); Class<?> parameterType = parameter.getParameterType(); if (Collection.class.isAssignableFrom(parameterType)) { Class<? extends Collection> collectionType = (Class<? extends Collection>) parameterType; Class<?> objectType = parameter.getParameterGenericType(); return parameterValue.toCollection(collectionType, objectType, pattern); } return parameterValue.to(parameterType, pattern); }