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 Summary

    Modifier and Type
    Method
    Description
    Return a builder for configuring JsonBinding instances.
    Create a default JsonBinding instance.
    Create a JsonBinding instance with the specified configuration.
    Create a JsonBinding instance using the provided consumer to configure it.
    <T> T
    deserialize(byte[] bytes, GenericType<T> type)
    Deserializes JSON from a byte array to an object of the specified generic type.
    <T> T
    deserialize(byte[] bytes, Class<T> type)
    Deserializes JSON from a byte array to an object of the specified type.
    <T> T
    Deserializes JSON from a parser to an object of the specified generic type.
    <T> T
    deserialize(JsonParser parser, Class<T> type)
    Deserializes JSON from a parser to an object of the specified type.
    <T> T
    deserialize(JsonValue jsonValue, GenericType<T> type)
    Deserializes a JsonValue to an object of the specified generic type.
    <T> T
    deserialize(JsonValue jsonValue, Class<T> type)
    Deserializes a JsonValue to an object of the specified type.
    <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.
    <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.
    <T> T
    deserialize(InputStream inputStream, GenericType<T> type)
    Deserializes JSON from an InputStream to an object of the specified generic type.
    <T> T
    deserialize(InputStream inputStream, Class<T> type)
    Deserializes JSON from an InputStream to an object of the specified type.
    <T> T
    deserialize(Reader reader, GenericType<T> type)
    Deserializes JSON from a Reader to an object of the specified generic type.
    <T> T
    deserialize(Reader reader, Class<T> type)
    Deserializes JSON from a Reader to an object of the specified type.
    <T> T
    deserialize(String jsonStr, GenericType<T> type)
    Deserializes JSON from a string to an object of the specified generic type.
    <T> T
    deserialize(String jsonStr, Class<T> type)
    Deserializes JSON from a string to an object of the specified type.
    default <T> List<T>
    deserializeList(byte[] bytes, Class<T> itemType)
    Deserializes a JSON array from a byte array to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(JsonParser parser, Class<T> itemType)
    Deserializes a JSON array from a parser to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(JsonValue jsonValue, Class<T> itemType)
    Deserializes a JSON array value to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(InputStream inputStream, int bufferSize, Class<T> itemType)
    Deserializes a JSON array from an InputStream with buffer size to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(InputStream inputStream, Class<T> itemType)
    Deserializes a JSON array from an InputStream to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(Reader reader, Class<T> itemType)
    Deserializes a JSON array from a Reader to a list of objects of the specified item type.
    default <T> List<T>
    deserializeList(String jsonStr, Class<T> itemType)
    Deserializes a JSON array from a string to a list of objects of the specified item type.
    void
    serialize(JsonGenerator generator, Object obj)
    Serializes an object to JSON using the provided generator.
    <T> void
    serialize(JsonGenerator generator, T obj, GenericType<? super T> type)
    Serializes an object of a generic type to JSON using the provided generator.
    <T> void
    serialize(JsonGenerator generator, T obj, Class<? super T> type)
    Serializes an object of a specific type to JSON using the provided generator.
    void
    serialize(OutputStream outputStream, Object obj)
    Serializes an object to JSON and writes it to an OutputStream.
    <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.
    <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.
    void
    serialize(Writer writer, Object obj)
    Serializes an object to JSON and writes it to a Writer.
    <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.
    <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.
    Serializes an object to a JSON string.
    <T> String
    serialize(T obj, GenericType<? super T> type)
    Serializes an object of a generic type to a JSON string.
    <T> String
    serialize(T obj, Class<? super T> type)
    Serializes an object of a specific type to a JSON string.
    default <T> void
    serializeList(JsonGenerator generator, List<T> values, Class<? super T> itemType)
    Serializes a list of objects of a specific item type to JSON using the provided generator.
    default <T> void
    serializeList(OutputStream outputStream, List<T> values, Class<? super T> itemType)
    Serializes a list of objects of a specific item type to JSON and writes it to an OutputStream.
    default <T> void
    serializeList(Writer writer, List<T> values, Class<? super T> itemType)
    Serializes a list of objects of a specific item type to JSON and writes it to a Writer.
    default <T> String
    serializeList(List<T> values, Class<? super T> itemType)
    Serializes a list of objects of a specific item type to a JSON string.
    default <T> byte[]
    serializeListToBytes(List<T> values, Class<? super T> itemType)
    Serializes a list of objects of a specific item type to JSON bytes encoded using UTF-8.
    byte[]
    Serializes an object to JSON bytes encoded using UTF-8.
    <T> byte[]
    serializeToBytes(T obj, GenericType<? super T> type)
    Serializes an object of a generic type to JSON bytes encoded using UTF-8.
    <T> byte[]
    serializeToBytes(T obj, Class<? super T> type)
    Serializes an object of a specific type to JSON bytes encoded using UTF-8.

    Methods inherited from interface RuntimeType.Api

    prototype
    Modifier and Type
    Method
    Description
    The prototype as it was received when creating this runtime object instance.
  • 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
    • serializeList

      default <T> String serializeList(List<T> values, Class<? super T> itemType)
      Serializes a list of objects of a specific item type to a JSON string. If the provided list is null, returns the string null. The item type determines the serializer used for each list item and may be a supertype of T.
      Type Parameters:
      T - the type of each list item
      Parameters:
      values - the list to serialize, this parameter may be null
      itemType - the type to use for serializing each list item
      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
    • serializeToBytes

      byte[] serializeToBytes(Object obj)
      Serializes an object to JSON bytes encoded using UTF-8. If the provided object is null, returns the bytes of the string null.
      Parameters:
      obj - the object to serialize, this parameter may be null
      Returns:
      the JSON bytes encoded using UTF-8
    • serializeToBytes

      <T> byte[] serializeToBytes(T obj, Class<? super T> type)
      Serializes an object of a specific type to JSON bytes encoded using UTF-8. If the provided object is null, returns the bytes of 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 bytes encoded using UTF-8
    • serializeListToBytes

      default <T> byte[] serializeListToBytes(List<T> values, Class<? super T> itemType)
      Serializes a list of objects of a specific item type to JSON bytes encoded using UTF-8. If the provided list is null, returns the bytes of the string null. The item type determines the serializer used for each list item and may be a supertype of T.
      Type Parameters:
      T - the type of each list item
      Parameters:
      values - the list to serialize, this parameter may be null
      itemType - the type to use for serializing each list item
      Returns:
      the JSON bytes encoded using UTF-8
    • serializeToBytes

      <T> byte[] serializeToBytes(T obj, GenericType<? super T> type)
      Serializes an object of a generic type to JSON bytes encoded using UTF-8. If the provided object is null, returns the bytes of 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 bytes encoded using UTF-8
    • 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
    • serializeList

      default <T> void serializeList(OutputStream outputStream, List<T> values, Class<? super T> itemType)
      Serializes a list of objects of a specific item type to JSON and writes it to an OutputStream. If the provided list is null, writes the bytes of the string null to the output stream. The item type determines the serializer used for each list item and may be a supertype of T.
      Type Parameters:
      T - the type of each list item
      Parameters:
      outputStream - the output stream to write to
      values - the list to serialize, this parameter may be null
      itemType - the type to use for serializing each list item
    • 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(JsonGenerator generator, Object obj)
      Serializes an object to JSON using the provided generator. If the provided object is null, writes null to the generator.
      Parameters:
      generator - the JSON generator to write to
      obj - the object to serialize, this parameter may be null
    • serialize

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

      default <T> void serializeList(JsonGenerator generator, List<T> values, Class<? super T> itemType)
      Serializes a list of objects of a specific item type to JSON using the provided generator. If the provided list is null, writes null to the generator. The item type determines the serializer used for each list item and may be a supertype of T.
      Type Parameters:
      T - the type of each list item
      Parameters:
      generator - the JSON generator to write to
      values - the list to serialize, this parameter may be null
      itemType - the type to use for serializing each list item
    • serialize

      <T> void serialize(JsonGenerator generator, T obj, GenericType<? super T> type)
      Serializes an object of a generic type to JSON using the provided generator. If the provided object is null, writes null to the generator.
      Type Parameters:
      T - the type of the object
      Parameters:
      generator - the JSON generator 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
    • serializeList

      default <T> void serializeList(Writer writer, List<T> values, Class<? super T> itemType)
      Serializes a list of objects of a specific item type to JSON and writes it to a Writer. If the provided list is null, writes the characters of null to the writer. The item type determines the serializer used for each list item and may be a supertype of T.
      Type Parameters:
      T - the type of each list item
      Parameters:
      writer - the writer to write to
      values - the list to serialize, this parameter may be null
      itemType - the type to use for serializing each list item
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(byte[] bytes, Class<T> itemType)
      Deserializes a JSON array from a byte array to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      bytes - the JSON data as bytes
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(String jsonStr, Class<T> itemType)
      Deserializes a JSON array from a string to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      jsonStr - the JSON string
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(InputStream inputStream, Class<T> itemType)
      Deserializes a JSON array from an InputStream to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      inputStream - the input stream containing JSON data
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(InputStream inputStream, int bufferSize, Class<T> itemType)
      Deserializes a JSON array from an InputStream with buffer size to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      inputStream - the input stream containing JSON data
      bufferSize - the buffer size for reading
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(Reader reader, Class<T> itemType)
      Deserializes a JSON array from a Reader to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      reader - the reader containing JSON data
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(JsonValue jsonValue, Class<T> itemType)
      Deserializes a JSON array value to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      jsonValue - the JSON value to deserialize
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • 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, or null when the input represents JSON null
    • deserialize

      <T> T deserialize(JsonParser parser, Class<T> type)
      Deserializes JSON from a parser to an object of the specified type.
      Type Parameters:
      T - the type of the object
      Parameters:
      parser - the parser containing JSON data
      type - the class type to deserialize to
      Returns:
      the deserialized object, or null when the input represents JSON null
    • deserializeList

      default <T> List<T> deserializeList(JsonParser parser, Class<T> itemType)
      Deserializes a JSON array from a parser to a list of objects of the specified item type.
      Type Parameters:
      T - the type of each list item
      Parameters:
      parser - the parser containing JSON data
      itemType - the class type of each list item
      Returns:
      the deserialized list, or null when the input represents JSON null
    • deserialize

      <T> T deserialize(JsonParser parser, GenericType<T> type)
      Deserializes JSON from a parser to an object of the specified generic type.
      Type Parameters:
      T - the type of the object
      Parameters:
      parser - the parser containing JSON data
      type - the generic type to deserialize to
      Returns:
      the deserialized object, or null when the input represents JSON null