Class VariantUtils

java.lang.Object
io.confluent.kafka.schemaregistry.type.VariantUtils

public class VariantUtils extends Object
Converts between Jackson JsonNode and Variant (metadata + value binary pair).
  • Constructor Details

    • VariantUtils

      public VariantUtils()
  • Method Details

    • toJsonNode

      public static com.fasterxml.jackson.databind.JsonNode toJsonNode(Variant variant)
      Converts a Variant into a Jackson JsonNode.

      Decimals are returned as a DecimalNode, so their serialized text depends on the caller's generator: a default generator may emit scientific notation for small-magnitude decimals. toJsonString(io.confluent.kafka.schemaregistry.type.Variant) is the canonical string form and always renders decimals in fixed-point.

      Parameters:
      variant - the Variant to convert
      Returns:
      a JsonNode representing the variant value
    • toJsonString

      public static String toJsonString(Variant variant)
      Converts a Variant into a JSON string. This is the canonical cross-language form: decimals are fixed-point (never scientific) and temporal types are ISO-8601 with the seconds field always present.
      Parameters:
      variant - the Variant to convert
      Returns:
      the JSON string representation
    • fromJson

      public static Variant fromJson(String json)
      Parses a JSON string into a Variant using the shared mapper. Bareword non-finite numbers (NaN, Infinity, -Infinity) are accepted, as are out-of-range magnitudes (1e400 becomes Infinity).
      Parameters:
      json - the JSON string to parse
      Returns:
      a Variant containing the encoded metadata and value
      Throws:
      IllegalArgumentException - if the JSON cannot be parsed
    • fromJsonNode

      public static Variant fromJsonNode(com.fasterxml.jackson.databind.JsonNode node)
      Converts a Jackson JsonNode into a Variant.
      Parameters:
      node - the JSON node to convert
      Returns:
      a Variant containing the encoded metadata and value