iluxa1810
iluxa1810

Reputation: 298

Response object scala.Unit

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?

Upvotes: 0

Views: 293

Answers (1)

Jasper-M
Jasper-M

Reputation: 15086

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

Upvotes: 3

Related Questions