Skip to content

Instantly share code, notes, and snippets.

@ctcarrier
Created October 20, 2011 04:32
Show Gist options
  • Save ctcarrier/1300421 to your computer and use it in GitHub Desktop.
Save ctcarrier/1300421 to your computer and use it in GitHub Desktop.
Spray lift-json support
implicit def liftJsonUnmarshaller[A :Manifest] = new UnmarshallerBase[A] {
val canUnmarshalFrom = ContentTypeRange(`application/json`) :: Nil
def unmarshal(content: HttpContent) = protect {
val jsonSource = DefaultUnmarshallers.StringUnmarshaller.unmarshal(content).right.get
parse(jsonSource).extract[A]
}
}
implicit def liftJsonMarshaller[A <: AnyRef] = new MarshallerBase[A] {
val canMarshalTo = ContentType(`application/json`) :: Nil
def marshal(value: A, contentType: ContentType) = {
val jsonSource = write(value)
DefaultMarshallers.StringMarshaller.marshal(jsonSource, contentType)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment