diff --git a/README.md b/README.md index 12d0dfa..8462b40 100644 --- a/README.md +++ b/README.md @@ -189,7 +189,7 @@ GET v1/customers?filter=age:GT:10 id:IN:[1,2,3] lastName:ISNOTNULL There are some special cases: - If we want to use `LIKE` filter and query values that include a percent sign, it needs to be URL encoded (%25). -- Dates must be in ISO-8601 format, `+` sign must be URL encoded (%2B). Single quotes for value are required. +- Dates and instants must be in ISO-8601 format, `+` sign must be URL encoded (%2B). Single quotes for value are required. ``` GET v1/customers?where=firstName:LIKE:'%somestring%25doe' GET v1/customers?where=createdAt:GT:'2017-06-12T11:57:00%2B00:00' diff --git a/core/src/main/java/com/kumuluz/ee/rest/utils/JPAUtils.java b/core/src/main/java/com/kumuluz/ee/rest/utils/JPAUtils.java index 35b751e..cd10984 100644 --- a/core/src/main/java/com/kumuluz/ee/rest/utils/JPAUtils.java +++ b/core/src/main/java/com/kumuluz/ee/rest/utils/JPAUtils.java @@ -41,6 +41,7 @@ import javax.persistence.metamodel.SingularAttribute; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.time.Instant; import java.time.ZonedDateTime; import java.time.format.DateTimeParseException; import java.util.*; @@ -351,6 +352,7 @@ private static CriteriaWhereQuery createWhereQueryInternal(CriteriaBuilder cb, R break; case GT: if (Date.class.isAssignableFrom(entityField.getJavaType()) || + Instant.class.isAssignableFrom(entityField.getJavaType()) || Number.class.isAssignableFrom(entityField.getJavaType()) || String.class.isAssignableFrom(entityField.getJavaType())) { @@ -363,6 +365,7 @@ private static CriteriaWhereQuery createWhereQueryInternal(CriteriaBuilder cb, R break; case GTE: if (Date.class.isAssignableFrom(entityField.getJavaType()) || + Instant.class.isAssignableFrom(entityField.getJavaType()) || Number.class.isAssignableFrom(entityField.getJavaType()) || String.class.isAssignableFrom(entityField.getJavaType())) { @@ -375,6 +378,7 @@ private static CriteriaWhereQuery createWhereQueryInternal(CriteriaBuilder cb, R break; case LT: if (Date.class.isAssignableFrom(entityField.getJavaType()) || + Instant.class.isAssignableFrom(entityField.getJavaType()) || Number.class.isAssignableFrom(entityField.getJavaType()) || String.class.isAssignableFrom(entityField.getJavaType())) { @@ -387,6 +391,7 @@ private static CriteriaWhereQuery createWhereQueryInternal(CriteriaBuilder cb, R break; case LTE: if (Date.class.isAssignableFrom(entityField.getJavaType()) || + Instant.class.isAssignableFrom(entityField.getJavaType()) || Number.class.isAssignableFrom(entityField.getJavaType()) || String.class.isAssignableFrom(entityField.getJavaType())) { @@ -531,6 +536,9 @@ private static Object getValueForPath(Path path, String value) { if (c.equals(Date.class)) return Date.from(ZonedDateTime.parse(value).toInstant()); + if (c.equals(Instant.class)) + return ZonedDateTime.parse(value).toInstant(); + if (c.equals(Boolean.class)) return Boolean.parseBoolean(value);