-
Notifications
You must be signed in to change notification settings - Fork 139
/
JwtJson4sJackson.scala
27 lines (22 loc) · 1.01 KB
/
JwtJson4sJackson.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package pdi.jwt
import org.json4s._
import org.json4s.JsonDSL.WithBigDecimal._
import org.json4s.jackson.JsonMethods._
import org.json4s.jackson.JsonMethods.{parse => jparse}
import org.json4s.jackson.Serialization
import org.json4s.jackson.Serialization.{read, write}
/**
* Implementation of `JwtCore` using `JObject` from Json4s Jackson.
*
* To see a full list of samples, check the [[http://pauldijou.fr/jwt-scala/samples/jwt-json4s/ online documentation]].
*/
object JwtJson4s extends JwtJson4sCommon with JwtJson4sImplicits {
protected def parse(value: String): JObject = jparse(value) match {
case res: JObject => res
case _ => throw new RuntimeException(s"Couldn't parse [$value] to a JObject")
}
protected def stringify(value: JObject): String = compact(render(value))
protected implicit val formats = Serialization.formats(NoTypeHints)
protected def parseHeader(header: String): JwtHeader = readHeader(parse(header))
protected def parseClaim(claim: String): JwtClaim = readClaim(parse(claim))
}