Skip to content

Commit

Permalink
Fix the jackson issue
Browse files Browse the repository at this point in the history
  • Loading branch information
roczei committed Oct 15, 2024
1 parent 2ccdaba commit 10e932d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions common/utils/src/main/scala/org/apache/spark/util/JsonUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ package org.apache.spark.util
import java.io.ByteArrayOutputStream
import java.nio.charset.StandardCharsets

import com.fasterxml.jackson.core.{JsonEncoding, JsonGenerator}
import com.fasterxml.jackson.core.{JsonEncoding, JsonFactory, JsonGenerator, StreamReadConstraints}
import com.fasterxml.jackson.databind.{DeserializationFeature, ObjectMapper}
import com.fasterxml.jackson.module.scala.DefaultScalaModule

import org.apache.spark.util.SparkErrorUtils.tryWithResource

private[spark] trait JsonUtils {

protected val mapper: ObjectMapper = new ObjectMapper().registerModule(DefaultScalaModule)
private val streamReadConstraints: StreamReadConstraints = StreamReadConstraints
.builder()
.maxStringLength(200)
.maxNestingDepth(200)
.maxNumberLength(200)
.build()

private val jsonFactory = new JsonFactory().setStreamReadConstraints(streamReadConstraints)

protected val mapper: ObjectMapper = new ObjectMapper(jsonFactory)
.registerModule(DefaultScalaModule)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)

def toJsonString(block: JsonGenerator => Unit): String = {
Expand Down

0 comments on commit 10e932d

Please sign in to comment.