java.lang.Object
codes.grow.packages.betterstack.core.Json

public final class Json extends Object
Shared Jackson configuration of the SDK.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> T
    decode(byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> type)
    Decodes JSON bytes into a generic type.
    static <T> T
    decode(byte[] bytes, Class<T> type)
    Decodes JSON bytes into a type.
    static byte[]
    encode(Object value)
    Encodes a value as UTF-8 JSON.
    static com.fasterxml.jackson.databind.ObjectMapper
    Returns the shared mapper.
    static String
    Encodes a value as a JSON string.
    static com.fasterxml.jackson.databind.JsonNode
    tree(byte[] bytes)
    Parses JSON bytes into a tree.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • mapper

      public static com.fasterxml.jackson.databind.ObjectMapper mapper()
      Returns the shared mapper. Do not reconfigure it.
      Returns:
      the mapper
    • encode

      public static byte[] encode(Object value)
      Encodes a value as UTF-8 JSON.
      Parameters:
      value - any Jackson-serialisable value
      Returns:
      the bytes
      Throws:
      ValidationException - when the value cannot be encoded
    • stringify

      public static String stringify(Object value)
      Encodes a value as a JSON string.
      Parameters:
      value - any Jackson-serialisable value
      Returns:
      the JSON text
      Throws:
      ValidationException - when the value cannot be encoded
    • decode

      public static <T> T decode(byte[] bytes, Class<T> type)
      Decodes JSON bytes into a type.
      Type Parameters:
      T - target type
      Parameters:
      bytes - UTF-8 JSON
      type - target class
      Returns:
      the value
      Throws:
      ValidationException - when the bytes are not valid JSON for the type
    • decode

      public static <T> T decode(byte[] bytes, com.fasterxml.jackson.core.type.TypeReference<T> type)
      Decodes JSON bytes into a generic type.
      Type Parameters:
      T - target type
      Parameters:
      bytes - UTF-8 JSON
      type - target type reference
      Returns:
      the value
      Throws:
      ValidationException - when the bytes are not valid JSON for the type
    • tree

      public static com.fasterxml.jackson.databind.JsonNode tree(byte[] bytes)
      Parses JSON bytes into a tree.
      Parameters:
      bytes - UTF-8 JSON
      Returns:
      the tree
      Throws:
      ValidationException - when the bytes are not valid JSON