Search code examples
cuba-platform

JPQL filter string with number value throws IllegalArgumentException in portal-app REST API V1


I want to get a customer by zip(String) by using this body:

{
  "entity": "demo$Customer",
  "query": "select c from demo$Customer c where c.zip = :zip",
  "params": [
        {
          "name": "zip",
          "value": "12345"
        }
    ]
}

I get this error:

java.lang.IllegalArgumentException: You have attempted to set a value of type class java.math.BigDecimal for parameter zip with expected type of class java.lang.String from query string select c from demo$Customer c where c.zip = :zip.

If I change the value to C12345 I get the data.

Is my params wrong or is that a bug while the value is a BigDecimal and the domain property is a String? How can I mark the vale as String explicitly?

Thanks for answers.


Solution

  • You have to specify the parameter type explicitly. You request will look like this:

    {
      "entity": "demo$Customer",
      "query": "select c from demo$Customer c where c.zip = :zip",
      "params": [
            {
              "name": "zip",
              "value": "123",
              "type": "string"
            }
        ]
    }

    Arguments with implicit types are handled successfully if you have a date or number argument with a specific format. When you have a string argument that looks like a date or number then the explicit type is required.