scala - Custom Response from Controller in Finatra -


in app have custom case class below bunch of additional fields.

case class user(id: uuid, username: string, password: string) 

now finatra controller picks response returned service , sends json response contains password hash well. controller basic gets

get("/users") {request: getusersrequest =>     userservice.users() } 

so question how customize response such can drop password field , add additional data well.

assuming userservice.users() returns list of users. i.e. list[user] transform response map.

for example, can map new case class.

case class userdto(id: uuid, username: string, comment: string) 

you can map tuple if don't want use class yet.

get("/users") {request: getusersrequest =>     userservice.users().map(u => userdto(u.id, u.username, "comment!")) } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -