Response object scala.Unit

265 views Asked by At

I have an action that returns Unit:

post("/settings") {
      blahblahblah...
      Unit
    }

Previously, the client received an empty response.

But after I upgraded the Scalatra version from 2.5.0 to 2.7.1 and Java from 8 to 11, the response now contains the following text:

object scala.Unit

enter image description here

How can I fix this?

1

There are 1 answers

3
Jasper-M On

Return the Unit value () instead of the Unit companion object (which has type Unit.type and is not an instance of type Unit).

post("/settings") {
  blahblahblah...
  ()
}

In scala 2.13 your code simply would not compile anymore. You get an error:

`Unit` companion object is not allowed in source; instead, use `()` for the unit value