Why can't I use Float as a service method parameter in EK9?

← Web Services · Ref: Q846

EK9 service method parameters are automatically parsed from HTTP request strings (query params, path params). Only types that can be safely parsed from strings are allowed. Float and Money are excluded because HTTP string representation loses precision.

ALLOWED TYPES

Integer, String, Date, Duration, DateTime, Time, Millisecond — all can be unambiguously parsed from a string.

EXCLUDED TYPES

Float — string representation is lossy (0.1 cannot be exactly represented)
Money — financial precision requires exact decimal parsing, not HTTP string conversion

CORRECT PATTERN

Use Integer for numeric parameters, String for text:

  findById() as GET for :/{userId}
    -> userId as Integer

See Q657 for URI mapping. See Q845 for return type requirement.

Example

defines module qa.webdeep.service.parameter.types

  defines constant

    JSON_TYPE <- "application/json"

  defines service

    <?-
      Service with valid parameter types.
      Parameters are parsed from HTTP request strings.
    -?>
    UserService :/users open

      findById() as GET for :/{userId}
        -> userId as Integer
        <- response as HTTPResponse: (capturedId: userId) with trait HTTPResponse
          override content()
            <- rtn as String: `{"userId": ${capturedId}}`
          override status() as pure
            <- rtn as Integer: 200
          override contentType() as pure
            <- rtn as String: JSON_TYPE
          override cacheControl() as pure
            <- rtn as String: "no-cache"
          override contentLanguage() as pure
            <- rtn as String: "en"
          default operator ?

      findByName() as GET for :/{userName}/profile
        -> userName as String
        <- response as HTTPResponse: (capturedName: userName) with trait HTTPResponse
          override content()
            <- rtn as String: `{"name": "${capturedName}"}`
          override status() as pure
            <- rtn as Integer: 200
          override contentType() as pure
            <- rtn as String: JSON_TYPE
          override cacheControl() as pure
            <- rtn as String: "max-age=60"
          override contentLanguage() as pure
            <- rtn as String: "en"
          default operator ?

  defines application

    UserApp
      register UserService()

  defines program

    ServiceParamDemo()
      stdout <- Stdout()
      stdout.println("Valid service parameter types: Integer, String, Date, Time")
      stdout.println("Invalid: Float (precision loss), Money (requires exact decimal)")

Common mistakes

E07760 — Float is not a valid service parameter type. HTTP string representation loses floating-point precision. Use Integer or String instead, and parse within the method if needed. See ek9 -h E07760 for details.

Incorrect:

      findByPrice() as GET for :/{price}
        -> price as Float

Correct:

      findById() as GET for :/{userId}
        -> userId as Integer
Other ways to ask this
  • What triggers E07760 SERVICE_INCOMPATIBLE_PARAM_TYPE_NON_REQUEST?
  • What parameter types are valid for EK9 service methods?
  • Why does EK9 restrict service parameter types?

Coming from another language?

Java Spring: @RequestParam binds to any type with a converter — no compile-time restriction. C# ASP.NET: model binding to complex types at runtime. Go: manual string parsing from http.Request. Python Flask: parameter converters registered at runtime. EK9: compile-time restriction to safely-parseable types prevents silent precision loss.

Keywords: E07760, service, parse, Integer, Float, type, parameter, HTTP