Skip to content

Commit

Permalink
Common: fix number deserialization in API Request Enrichment (close #383
Browse files Browse the repository at this point in the history
)
  • Loading branch information
oguzhanunlu committed Oct 28, 2020
1 parent 2b7d9d9 commit 8b136d3
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ package com.snowplowanalytics.snowplow.enrich.common
package enrichments.registry.apirequest

import cats.syntax.either._
import com.fasterxml.jackson.core.{JsonFactory, JsonParser}
import com.snowplowanalytics.snowplow.enrich.common.utils.CirceUtils
import com.snowplowanalytics.snowplow.enrich.common.utils.JsonPath.{query, wrapArray}
import io.circe._
import io.circe.parser._
import io.circe.syntax._

import utils.JsonPath.{query, wrapArray}

/**
* Base trait for API output format. Primary intention of these classes is to perform transformation
* of API raw output to self-describing JSON instance
Expand Down Expand Up @@ -117,6 +117,9 @@ final case class JsonOutput(jsonPath: String) extends ApiOutput[Json] {
case other => other.leftMap(JsonPathException.apply)
}

private[this] val jsonFactory: JsonFactory = new JsonFactory(CirceUtils.mapper)
def parseResponse(response: String): Either[Throwable, Json] =
parse(response)
Either
.catchNonFatal[JsonParser](jsonFactory.createParser(response))
.flatMap(parser => Either.catchNonFatal[Json](CirceUtils.mapper.readValue(parser, classOf[Json])))
}

0 comments on commit 8b136d3

Please sign in to comment.