Created
September 17, 2012 21:19
-
-
Save devnulled/3739869 to your computer and use it in GitHub Desktop.
Simple Helper Class to return JSON Responses in Lift with a particular HTTP Status Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package your.mom | |
| import net.liftweb.http.{S, HeaderDefaults, InMemoryResponse, LiftResponse} | |
| import net.liftweb.json.JsonAST.JValue | |
| import net.liftweb.json._ | |
| // This is much nicer to use than the native JsonResponse in Lift | |
| case class WrappedLiftJsonResponse(json: JValue, statusCode: Int, respHeaders: List[(String, String)] = Nil) extends LiftResponse with HeaderDefaults { | |
| val headerContentType = "Content-Type" | |
| val headerJsonContentValue = "application/json" | |
| def toResponse = { | |
| val jsonHeader = List((headerContentType, headerJsonContentValue)) | |
| val jsonString = compact(render(json)) | |
| InMemoryResponse(jsonString.getBytes("UTF-8"), jsonHeader ++ respHeaders, cookies, statusCode) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment