Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Commit

Permalink
Fix compilation issue with Json4sSupport
Browse files Browse the repository at this point in the history
  • Loading branch information
Heiko Seeberger committed Dec 20, 2018
1 parent 674a105 commit 75cc1f7
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
package de.heikoseeberger.akkahttpjson4s

import java.lang.reflect.InvocationTargetException

import akka.http.scaladsl.marshalling.{ Marshaller, ToEntityMarshaller }
import akka.http.scaladsl.model.ContentTypeRange
import akka.http.scaladsl.model.MediaType
import akka.http.scaladsl.model.MediaTypes.`application/json`
import akka.http.scaladsl.unmarshalling.{ FromEntityUnmarshaller, Unmarshaller }
import akka.stream.Materializer
import akka.util.ByteString
import org.json4s.{ Formats, MappingException, Serialization }
import scala.collection.immutable.Seq
import scala.concurrent.ExecutionContext

/**
* Automatic to and from JSON marshalling/unmarshalling using an in-scope *Json4s* protocol.
Expand Down Expand Up @@ -77,9 +78,7 @@ trait Json4sSupport {
formats: Formats): FromEntityUnmarshaller[A] =
jsonStringUnmarshaller
.map(s => serialization.read(s))
.recover { _ => _ =>
{ case MappingException(_, ite: InvocationTargetException) => throw ite.getCause }
}
.recover(throwCause)

/**
* `A` => HTTP entity
Expand All @@ -97,4 +96,10 @@ trait Json4sSupport {
case ShouldWritePretty.True =>
jsonStringMarshaller.compose(serialization.writePretty[A])
}

private def throwCause[A](
ec: ExecutionContext
)(mat: Materializer): PartialFunction[Throwable, A] = {
case MappingException(_, e: InvocationTargetException) => throw e.getCause
}
}

0 comments on commit 75cc1f7

Please sign in to comment.