dcoliversun commented on code in PR #36885:
URL: https://github.com/apache/spark/pull/36885#discussion_r899860638
##########
core/src/main/scala/org/apache/spark/util/JsonProtocol.scala:
##########
@@ -57,298 +57,398 @@ import org.apache.spark.util.Utils.weakIntern
private[spark] object JsonProtocol {
// TODO: Remove this file and put JSON serialization into each individual
class.
- private implicit val format = DefaultFormats
-
private val mapper = new ObjectMapper().registerModule(DefaultScalaModule)
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
/** ------------------------------------------------- *
* JSON serialization methods for SparkListenerEvents |
* -------------------------------------------------- */
- def sparkEventToJson(event: SparkListenerEvent): JValue = {
+ def sparkEventToJsonString(event: SparkListenerEvent): String = {
+ toJsonString { generator =>
+ writeSparkEventToJson(event, generator)
+ }
+ }
+
+ def toJsonString(block: JsonGenerator => Unit): String = {
+ val baos = new ByteArrayOutputStream()
+ val generator = mapper.createGenerator(baos, JsonEncoding.UTF8)
+ block(generator)
+ generator.close()
+ new String(baos.toByteArray, StandardCharsets.UTF_8)
Review Comment:
Better to close `baos` after `baos.toByteArray`
##########
core/src/test/scala/org/apache/spark/deploy/history/FsHistoryProviderSuite.scala:
##########
@@ -1730,13 +1729,13 @@ abstract class FsHistoryProviderSuite extends
SparkFunSuite with Matchers with L
val bstream = new BufferedOutputStream(cstream)
val metadata = SparkListenerLogStart(org.apache.spark.SPARK_VERSION)
- val eventJson = JsonProtocol.logStartToJson(metadata)
- val metadataJson = compact(eventJson) + "\n"
+ val eventJson = JsonProtocol.sparkEventToJsonString(metadata)
Review Comment:
Don't use `eventJson` because it's String
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]