Class SafeJsonSerializer

Object
org.apache.spark.sql.streaming.SafeJsonSerializer

public class SafeJsonSerializer extends Object
  • Constructor Details

    • SafeJsonSerializer

      public SafeJsonSerializer()
  • Method Details

    • safeDoubleToJValue

      public static org.json4s.JValue safeDoubleToJValue(double value)
      Convert Double to JValue while handling empty or infinite values
    • safeMapToJValue

      public static <T> org.json4s.JValue safeMapToJValue(Map<String,T> map, scala.Function2<String,T,org.json4s.JValue> valueToJValue)
      Convert map to JValue while handling empty maps. Also, this sorts the keys. Function is written as generic (T) to handle variety of types - Returns JNothing if the map is null or empty. - Sorts the keys alphabetically to ensure deterministic JSON output. - Converts each map entry to a JValue using the provided function, which also receives the key. - Combines all entries into a single JObject.

      Parameters:
      map - A Java Map[String, T] to convert
      valueToJValue - Function that takes a key and value and returns a corresponding JValue
      Returns:
      A JObject representing the map, or JNothing if the map is null or empty
    • safeDecimalToJValue

      public static org.json4s.JValue safeDecimalToJValue(double value)
      Convert BigDecimal to JValue while handling empty or infinite values