Skip to content

Commit

Permalink
Align upickle PR with project
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldijou committed Jan 13, 2017
1 parent 4ca463c commit d495685
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
File renamed without changes.
7 changes: 7 additions & 0 deletions docs/src/site/samples/jwt-upickle/index.html
@@ -0,0 +1,7 @@
---
layout: sample
project: uPickle
---

{% capture jwtUpickle %}{% include tut/jwt-upickle-jwt-upickle.md %}{% endcapture %}
{{ jwtUpickle | markdownify }}
17 changes: 9 additions & 8 deletions json/upickle/src/main/scala/JwtUpickle.scala
Expand Up @@ -5,23 +5,24 @@ import upickle.json
import upickle.default._

/**
* Created by alonsodomin on 07/09/2016.
* Implementation of `JwtCore` using `Js.Value` from uPickle.
*
* To see a full list of samples, check the [[http://pauldijou.fr/jwt-scala/samples/jwt-upickle/ online documentation]].
*/
object JwtUpickle extends JwtJsonCommon[Js.Value] with JwtUpickleImplicits {
override protected def parse(value: String): Js.Value = json.read(value)
object JwtUpickle extends JwtJsonCommon[Js.Value] {
protected def parse(value: String): Js.Value = json.read(value)

override protected def stringify(value: Js.Value): String = json.write(value)
protected def stringify(value: Js.Value): String = json.write(value)

override protected def getAlgorithm(header: Js.Value): Option[JwtAlgorithm] = header match {
protected def getAlgorithm(header: Js.Value): Option[JwtAlgorithm] = header match {
case obj: Js.Obj =>
val fields = obj.value.toMap
fields.get("alg").flatMap(alg => JwtAlgorithm.optionFromString(alg.str))

case _ => None
}

override protected def parseHeader(header: String): JwtHeader = read[JwtHeader](header)

override protected def parseClaim(claim: String): JwtClaim = read[JwtClaim](claim)
protected def parseHeader(header: String): JwtHeader = read[JwtHeader](header)
protected def parseClaim(claim: String): JwtClaim = read[JwtClaim](claim)

}
5 changes: 1 addition & 4 deletions json/upickle/src/main/scala/JwtUpickleImplicits.scala
Expand Up @@ -4,10 +4,7 @@ import upickle.Js
import upickle.json
import upickle.default._

/**
* Created by alonsodomin on 07/09/2016.
*/
private[jwt] trait JwtUpickleImplicits {
trait JwtUpickleImplicits {

implicit def headerReader: Reader[JwtHeader] = Reader[JwtHeader] {
case obj: Js.Obj =>
Expand Down
3 changes: 3 additions & 0 deletions json/upickle/src/main/scala/package.scala
@@ -0,0 +1,3 @@
package pdi

package object jwt extends JwtUpickleImplicits {}

0 comments on commit d495685

Please sign in to comment.