Interface JsonBinding

All Superinterfaces:
RuntimeType.Api<JsonBindingConfig>

public interface JsonBinding extends RuntimeType.Api<JsonBindingConfig>
Main interface for JSON binding operations.

This interface provides methods for serializing Java objects to JSON and deserializing JSON back to Java objects. It supports various input/output formats including strings, streams, readers, writers, and byte arrays.

Serialization methods must accept null as the value to serialize.
  • Method Details

    • create

      static JsonBinding create()
      Create a default JsonBinding instance.
      Returns:
      a new JsonBinding instance with default configuration
    • builder

      static JsonBindingConfig.Builder builder()
      Return a builder for configuring JsonBinding instances.
      Returns:
      a JsonBindingConfig.Builder
    • create

      static JsonBinding create(JsonBindingConfig config)
      Create a JsonBinding instance with the specified configuration.
      Parameters:
      config - the configuration to use
      Returns:
      a new JsonBinding instance
    • create

      static JsonBinding create(Consumer<JsonBindingConfig.Builder> consumer)
      Create a JsonBinding instance using the provided consumer to configure it.
      Parameters:
      consumer - the consumer to configure the builder
      Returns:
      a new JsonBinding instance
    • serialize

      String serialize(Object obj)
      Serializes an object to a JSON string. If the provided object is null, returns the string null.
      Parameters:
      obj - the object to serialize, this parameter may be null
      Returns:
      the JSON string representation
    • serialize

      <T> String serialize(T obj, Class<? super T> type)
      Serializes an object of a specific type to a JSON string. If the provided object is null, returns the string null.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize, this parameter may be null
      type - the class type of the object
      Returns:
      the JSON string representation
    • serialize

      <T> String serialize(T obj, GenericType<? super T> type)
      Serializes an object of a generic type to a JSON string. If the provided object is null, returns the string null.
      Type Parameters:
      T - the type of the object
      Parameters:
      obj - the object to serialize, this parameter may be null
      type - the generic type of the object
      Returns:
      the JSON string representation
    • serialize

      void serialize(OutputStream outputStream, Object obj)
      Serializes an object to JSON and writes it to an OutputStream. If the provided object is null, writes the bytes of the string null to the output stream.
      Parameters:
      outputStream - the output stream to write to
      obj - the object to serialize, this parameter may be null
    • serialize

      <T> void serialize(OutputStream outputStream, T obj, Class<? super T> type)
      Serializes an object of a specific type to JSON and writes it to an OutputStream. If the provided object is null, writes the bytes of the string null to the output stream.
      Type Parameters:
      T - the type of the object
      Parameters:
      outputStream - the output stream to write to
      obj - the object to serialize, this parameter may be null
      type - the class type of the object
    • serialize

      <T> void serialize(OutputStream outputStream, T obj, GenericType<? super T> type)
      Serializes an object of a generic type to JSON and writes it to an OutputStream. If the provided object is null, writes the bytes of the string null to the output stream.
      Type Parameters:
      T - the type of the object
      Parameters:
      outputStream - the output stream to write to
      obj - the object to serialize, this parameter may be null
      type - the generic type of the object
    • serialize

      void serialize(Writer writer, Object obj)
      Serializes an object to JSON and writes it to a Writer. If the provided object is null, writes the characters of null to the writer.
      Parameters:
      writer - the writer to write to
      obj - the object to serialize, this parameter may be null
    • serialize

      <T> void serialize(Writer writer, T obj, Class<? super T> type)
      Serializes an object of a specific type to JSON and writes it to a Writer. If the provided object is null, writes the characters of null to the writer.
      Type Parameters:
      T - the type of the object
      Parameters:
      writer - the writer to write to
      obj - the object to serialize, this parameter may be null
      type - the class type of the object
    • serialize

      <T> void serialize(Writer writer, T obj, GenericType<? super T> type)
      Serializes an object of a generic type to JSON and writes it to a Writer. If the provided object is null, writes the characters of null to the writer.
      Type Parameters:
      T - the type of the object
      Parameters:
      writer - the writer to write to
      obj - the object to serialize, this parameter may be null
      type - the generic type of the object
    • deserialize

      <T> T deserialize(byte[] bytes, Class<T> type)
      Deserializes JSON from a byte array to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      bytes - the JSON data as bytes
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(byte[] bytes, GenericType<T> type)
      Deserializes JSON from a byte array to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      bytes - the JSON data as bytes
      type - the generic type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(String jsonStr, Class<T> type)
      Deserializes JSON from a string to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      jsonStr - the JSON string
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(String jsonStr, GenericType<T> type)
      Deserializes JSON from a string to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      jsonStr - the JSON string
      type - the generic type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(InputStream inputStream, Class<T> type)
      Deserializes JSON from an InputStream to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      inputStream - the input stream containing JSON data
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(InputStream inputStream, GenericType<T> type)
      Deserializes JSON from an InputStream to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      inputStream - the input stream containing JSON data
      type - the generic type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(InputStream inputStream, int bufferSize, Class<T> type)
      Deserializes JSON from an InputStream with buffer size to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      inputStream - the input stream containing JSON data
      bufferSize - the buffer size for reading
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(InputStream inputStream, int bufferSize, GenericType<T> type)
      Deserializes JSON from an InputStream with buffer size to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      inputStream - the input stream containing JSON data
      bufferSize - the buffer size for reading
      type - the generic type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(Reader reader, Class<T> type)
      Deserializes JSON from a Reader to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      reader - the reader containing JSON data
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(Reader reader, GenericType<T> type)
      Deserializes JSON from a Reader to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      reader - the reader containing JSON data
      type - the generic type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(JsonValue jsonValue, Class<T> type)
      Deserializes a JsonValue to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      jsonValue - the JsonValue to deserialize
      type - the class type to deserialize to
      Returns:
      the deserialized object
    • deserialize

      <T> T deserialize(JsonValue jsonValue, GenericType<T> type)
      Deserializes a JsonValue to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      jsonValue - the JsonValue to deserialize
      type - the generic type to deserialize to
      Returns:
      the deserialized object