Skip to content

Commit

Permalink
Mitigation of Play-JSON DoS playframework/play-json#180
Browse files Browse the repository at this point in the history
  • Loading branch information
plokhotnyuk committed Sep 18, 2018
1 parent 9e30202 commit 354d502
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import com.github.plokhotnyuk.jsoniter_scala.macros.UPickleReaderWriters._
import io.circe.parser._
import io.circe.syntax._
import org.openjdk.jmh.annotations.{Benchmark, Param, Setup}
import play.api.libs.json.Json
import play.api.libs.json._
import upickle.default._

import scala.collection.JavaConverters._
import scala.util.Try

class ArrayOfZonedDateTimesBenchmark extends CommonParams {
val zoneIds: Array[ZoneId] = ZoneId.getAvailableZoneIds.asScala.map(ZoneId.of).toArray
Expand Down Expand Up @@ -46,6 +47,10 @@ class ArrayOfZonedDateTimesBenchmark extends CommonParams {
preallocatedBuf = new Array[Byte](jsonBytes.length + preallocatedOff + 100/*to avoid possible out of bounds error*/)
}

implicit val zonedDateTimeArrayFormat: Format[ZonedDateTime] = Format(
Reads(js => Try(JsSuccess(ZonedDateTime.parse(js.as[JsString].value))).getOrElse(JsError.apply)),
Writes(v => JsString(v.toString)))

@Benchmark
def readAVSystemGenCodec(): Array[ZonedDateTime] = JsonStringInput.read[Array[ZonedDateTime]](new String(jsonBytes, UTF_8))

Expand Down

0 comments on commit 354d502

Please sign in to comment.