Github user vanzin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/9297#discussion_r44481020
  
    --- Diff: core/src/main/scala/org/apache/spark/util/JsonProtocol.scala ---
    @@ -96,6 +114,7 @@ private[spark] object JsonProtocol {
             executorMetricsUpdateToJson(metricsUpdate)
           case blockUpdated: SparkListenerBlockUpdated =>
             throw new MatchError(blockUpdated)  // TODO(ekl) implement this
    +      case _ => parse(write(event))
    --- End diff --
    
    Hmm... I'm not sure I like this. This is why you need the class list above, 
when it would be much nicer to not need it. You can avoid the class list by 
using the Jackson API directly. For example:
    
        import com.fasterxml.jackson.annotation._
        import com.fasterxml.jackson.databind.ObjectMapper
        
        @JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, 
include=JsonTypeInfo.As.PROPERTY, property="Event") class A { }
        
        class B(val bar: String, val baz: Option[String]) extends A
        
        object main {
          def main(args: Array[String]): Unit = {
            val mapper = new ObjectMapper()
            
mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule)
        
            val b = new B("bar", None)
            val out = mapper.writeValueAsString(b)
        
            val read = mapper.readValue(out, classOf[A]).asInstanceOf[B]
            println(s"$read: ${read.bar} :: ${read.baz}")
          }
        }
        
    Basically, annotate the root event (`SparkEventListener`) with 
`JsonTypeInfo`, and use an `ObjectMapper` to generate and parse the JSON.
    
    I tried but couldn't make this work with `DefaultParams`. Setting just 
`typeHintFieldName` doesn't work, it seems you need `typeHints`, and for that 
you need a class list. It seems to just ignore the annotations.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to