I would like to know if there is any way to return Java object as Json String inside spray routing.

For now, I am converting my Java object (which is returned my UserActor) into Json using Jackson through a util class(JacksonUtil) created by me.

Here is the code snippet for reference : 

```
val route = {
    path("users" / Segment) { id =>
      parameterMap { params =>
        get {
          respondWithMediaType(MediaTypes.`text/plain`) {
            val resource: GetResource = new GetResource
            resource.searchCriteriaList.add(new SearchCriteria("userId", "=", Segment)) 
            logger.info("Request Received in new route: " + resource)
            onComplete(callUserActor(resource)) {
              case Success(ret: User) => {
                logger.info("Request complete. Success.")
                complete(JacksonUtil.toJson(ret))
              }
              case Failure(error) => {
                logger.info("Request complete. Failure. " + error)
                complete("Error: " + error)
              }
            }
          }
        }
      }
    } 
  }

def callUserActor(getResource: GetResource): Future[User] = {
    (userActor ? getResource).mapTo[User]
  }

```

GetResource is the class which take of query parameters.
For example if client hits GET /users/123, then GetResource will add a searchcriteria as userId = "123"