I inherited a legacy Scalatra application which offers a REST API. The serialisation of the returned object works perfectly if the returned object is a case class build on other case classes. But if return a object created from a Java or Scala class it is not serialised by Scalatra. I will get only the result of Object.toString(). So what do I need to do serialise also non case classes properly?
Here is my class
class Snafu(sna: String, foo: String) {
}
and this is my servlet:
class HealthServlet(implicit inj: Injector)
extends ScalatraServlet with SLF4JLogging
with JacksonJsonSupport
with Injectable with InternalViaLocalhostOnlySupport {
protected implicit val jsonFormats: Formats = DefaultFormats
val healthStateCheck = inject[HealthStateCheck]
before("/") {
}
get("/") {
Ok(new Snafu("4", "2"))
}
}