Fix unmarshal for czech post delivery
This commit is contained in:
@@ -189,7 +189,7 @@ object CzechPostDeliveryCheck {
|
||||
case Success(response) => if (response.status.isSuccess()) Success(response) else Failure(new Exception(s"Check parcel returned HTTP status: ${response.status.value}."))
|
||||
case response: Failure[HttpResponse] => response
|
||||
}
|
||||
.flatMap(response => Unmarshal(response).to[Array[Entities.ParcelHistory]])
|
||||
.flatMap(response => Unmarshal(response).to[Seq[Entities.ParcelHistory]])
|
||||
.andThen {
|
||||
case Success(parcelHistories) =>
|
||||
parcelHistories.foreach(parcelHistory => ctx.self ! ParcelHistoryRetrieved(parcelHistory))
|
||||
|
||||
@@ -10,6 +10,7 @@ import akka.http.scaladsl.Http
|
||||
import akka.util.Timeout
|
||||
import akka.{ actor, Done }
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import de.heikoseeberger.akkahttpjackson.JacksonSupport
|
||||
|
||||
import scala.concurrent.duration._
|
||||
@@ -18,6 +19,7 @@ import scala.io.StdIn
|
||||
|
||||
object Main {
|
||||
JacksonSupport.defaultObjectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY)
|
||||
JacksonSupport.defaultObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
|
||||
def main(args: Array[String]): Unit = {
|
||||
val botId = System.getProperty("botId", "570855144:AAEv7b817cuq2JJI9f2kG5B9G3zW1x-btz4")
|
||||
|
||||
38
src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala
Normal file
38
src/test/scala/eu/xeppaka/bot/UnmarshalSpec.scala
Normal file
@@ -0,0 +1,38 @@
|
||||
package eu.xeppaka.bot
|
||||
|
||||
import akka.actor.testkit.typed.scaladsl.ActorTestKit
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.http.scaladsl.model.{ ContentTypes, HttpEntity }
|
||||
import akka.http.scaladsl.unmarshalling.Unmarshal
|
||||
import akka.util.ByteString
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import de.heikoseeberger.akkahttpjackson.JacksonSupport
|
||||
import org.scalatest.BeforeAndAfterAll
|
||||
import org.scalatest.flatspec.AnyFlatSpec
|
||||
|
||||
import scala.concurrent.Await
|
||||
import scala.concurrent.duration.DurationInt
|
||||
|
||||
class UnmarshalSpec extends AnyFlatSpec with BeforeAndAfterAll {
|
||||
import de.heikoseeberger.akkahttpjackson.JacksonSupport._
|
||||
|
||||
private var testkit: ActorTestKit = _
|
||||
|
||||
override protected def beforeAll(): Unit = {
|
||||
JacksonSupport.defaultObjectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
|
||||
testkit = ActorTestKit()
|
||||
}
|
||||
|
||||
override protected def afterAll(): Unit = {
|
||||
testkit.shutdownTestKit()
|
||||
}
|
||||
|
||||
"test unmarshal" should "ok" in {
|
||||
implicit val system: ActorSystem[Nothing] = testkit.system
|
||||
val json =
|
||||
"[{\"attributes\":{\"parcelType\":\"1 \",\"weight\":0,\"currency\":\"\",\"telefonTyp\":null,\"telefonNazev\":null,\"telefonCislo\":null,\"dobirka\":0,\"kusu\":null,\"ulozeniDo\":null,\"ulozniDoba\":null,\"zemePuvodu\":null,\"zemeUrceni\":null,\"dorucovaniDate\":null,\"dorucovaniOd\":null,\"dorucovaniDo\":null},\"states\":{\"state\":[{\"id\":\"-4\",\"date\":\"2020-12-27\",\"text\":\"Pro tento druh zásilek Česká pošta informace nezobrazuje.\",\"postcode\":null,\"postoffice\":null,\"idIcon\":null,\"publicAccess\":0,\"latitude\":null,\"longitude\":null,\"timeDeliveryAttempt\":null}]},\"id\":\"123456\"}]"
|
||||
val entity = HttpEntity(contentType = ContentTypes.`application/json`, data = ByteString(json))
|
||||
val result = Await.result(Unmarshal(json).to[Seq[Entities.ParcelHistory]], 2.seconds)
|
||||
println(result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user