Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-8659

Can't filter when attribute type is LocalDate or LocalDateTime

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 3.4.6, 3.5.1, 4.0.0
    • JAX-RS
    • Moderate

    Description

      When trying to filter using fiql language : 

            filter:"closingDate=gt=2014-11-04"

      with closingDate is of type LocalDate.

      We get the exception "Cannot convert String Value to a value of class LocalDate"

       

      Cause : in AbstractSearchConditionParser:: ParseType :

                  if (Date.class.isAssignableFrom(valueType)) {
                      castedValue = convertToDate(valueType, value);
                  } else {
                      boolean isPrimitive = InjectionUtils.isPrimitive(valueType);
                      boolean isPrimitiveOrEnum = isPrimitive || valueType.isEnum();
                      if (ownerBean == null || isPrimitiveOrEnum) {
                          try {
                              CollectionCheck collCheck = getCollectionCheck(originalPropName, isCollection, actualType);
                              if (collCheck == null) {
                                  castedValue = InjectionUtils.convertStringToPrimitive(value, actualType);
                              }
                              if (collCheck == null && isCollection) {
                                  castedValue = getCollectionSingleton(valueType, castedValue);
                              } else if (isCollection) {
                                  typeInfo.setCollectionCheckInfo(new CollectionCheckInfo(collCheck, castedValue));
                                  castedValue = getEmptyCollection(valueType);
                              }
                          } catch (Exception e) {
                              throw new SearchParseException("Cannot convert String value \"" + value
                                                           + "\" to a value of class " + valueType.getName(), e);
                          }
                      } else {
                          Class<?> classType = isCollection ? valueType : value.getClass();
                          try {
                              Method setterM = valueType.getMethod("set" + getMethodNameSuffix(setter),
                                                                   new Class[]{classType});
                              Object objectValue = !isCollection ? value : getCollectionSingleton(valueType, value);
                              setterM.invoke(ownerBean, new Object[]{objectValue});
                              castedValue = objectValue;
                          } catch (Throwable ex) {
                              throw new SearchParseException("Cannot convert String value \"" + value
                                                             + "\" to a value of class " + valueType.getName(), ex);
                          }                }
                  } 

      {}-> here the code consider LocalDate as a primitive Type and tries to cast it.
      -> Can we consider adding LocalDate and LocalDateTime types like doing with the Date type ?

       

      Attachments

        Issue Links

          Activity

            People

              reta Andriy Redko
              abelkahla Achraf BELKAHLA
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: