Interface JsonBinding
- All Superinterfaces:
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 TypeMethodDescriptionstatic JsonBindingConfig.Builderbuilder()Return a builder for configuring JsonBinding instances.static JsonBindingcreate()Create a default JsonBinding instance.static JsonBindingcreate(JsonBindingConfig config) Create a JsonBinding instance with the specified configuration.static JsonBindingcreate(Consumer<JsonBindingConfig.Builder> consumer) Create a JsonBinding instance using the provided consumer to configure it.<T> Tdeserialize(byte[] bytes, GenericType<T> type) Deserializes JSON from a byte array to an object of the specified generic type.<T> Tdeserialize(byte[] bytes, Class<T> type) Deserializes JSON from a byte array to an object of the specified type.<T> Tdeserialize(JsonParser parser, GenericType<T> type) Deserializes JSON from a parser to an object of the specified generic type.<T> Tdeserialize(JsonParser parser, Class<T> type) Deserializes JSON from a parser to an object of the specified type.<T> Tdeserialize(JsonValue jsonValue, GenericType<T> type) Deserializes a JsonValue to an object of the specified generic type.<T> Tdeserialize(JsonValue jsonValue, Class<T> type) Deserializes a JsonValue to an object of the specified type.<T> Tdeserialize(InputStream inputStream, int bufferSize, GenericType<T> type) Deserializes JSON from an InputStream with buffer size to an object of the specified generic type.<T> Tdeserialize(InputStream inputStream, int bufferSize, Class<T> type) Deserializes JSON from an InputStream with buffer size to an object of the specified type.<T> Tdeserialize(InputStream inputStream, GenericType<T> type) Deserializes JSON from an InputStream to an object of the specified generic type.<T> Tdeserialize(InputStream inputStream, Class<T> type) Deserializes JSON from an InputStream to an object of the specified type.<T> Tdeserialize(Reader reader, GenericType<T> type) Deserializes JSON from a Reader to an object of the specified generic type.<T> Tdeserialize(Reader reader, Class<T> type) Deserializes JSON from a Reader to an object of the specified type.<T> Tdeserialize(String jsonStr, GenericType<T> type) Deserializes JSON from a string to an object of the specified generic type.<T> Tdeserialize(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.voidserialize(JsonGenerator generator, Object obj) Serializes an object to JSON using the provided generator.<T> voidserialize(JsonGenerator generator, T obj, GenericType<? super T> type) Serializes an object of a generic type to JSON using the provided generator.<T> voidserialize(JsonGenerator generator, T obj, Class<? super T> type) Serializes an object of a specific type to JSON using the provided generator.voidserialize(OutputStream outputStream, Object obj) Serializes an object to JSON and writes it to an OutputStream.<T> voidserialize(OutputStream outputStream, T obj, GenericType<? super T> type) Serializes an object of a generic type to JSON and writes it to an OutputStream.<T> voidserialize(OutputStream outputStream, T obj, Class<? super T> type) Serializes an object of a specific type to JSON and writes it to an OutputStream.voidSerializes an object to JSON and writes it to a Writer.<T> voidserialize(Writer writer, T obj, GenericType<? super T> type) Serializes an object of a generic type to JSON and writes it to a Writer.<T> voidSerializes an object of a specific type to JSON and writes it to a Writer.Serializes an object to a JSON string.<T> Stringserialize(T obj, GenericType<? super T> type) Serializes an object of a generic type to a JSON string.<T> StringSerializes an object of a specific type to a JSON string.default <T> voidserializeList(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> voidserializeList(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> voidserializeList(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> StringserializeList(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[]serializeToBytes(Object obj) 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
prototypeModifier and TypeMethodDescriptionThe prototype as it was received when creating this runtime object instance.
-
Method Details
-
create
Create a default JsonBinding instance.- Returns:
- a new JsonBinding instance with default configuration
-
builder
Return a builder for configuring JsonBinding instances.- Returns:
- a JsonBindingConfig.Builder
-
create
Create a JsonBinding instance with the specified configuration.- Parameters:
config- the configuration to use- Returns:
- a new JsonBinding instance
-
create
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
-
serialize
Serializes an object of a specific type to a JSON string. If the provided object is null, returns the stringnull.- Type Parameters:
T- the type of the object- Parameters:
obj- the object to serialize, this parameter may benulltype- the class type of the object- Returns:
- the JSON string representation
-
serializeList
Serializes a list of objects of a specific item type to a JSON string. If the provided list is null, returns the stringnull. The item type determines the serializer used for each list item and may be a supertype ofT.- Type Parameters:
T- the type of each list item- Parameters:
values- the list to serialize, this parameter may benullitemType- the type to use for serializing each list item- Returns:
- the JSON string representation
-
serialize
Serializes an object of a generic type to a JSON string. If the provided object is null, returns the stringnull.- Type Parameters:
T- the type of the object- Parameters:
obj- the object to serialize, this parameter may benulltype- the generic type of the object- Returns:
- the JSON string representation
-
serializeToBytes
Serializes an object to JSON bytes encoded using UTF-8. If the provided object is null, returns the bytes of the stringnull.- Parameters:
obj- the object to serialize, this parameter may benull- Returns:
- the JSON bytes encoded using UTF-8
-
serializeToBytes
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 stringnull.- Type Parameters:
T- the type of the object- Parameters:
obj- the object to serialize, this parameter may benulltype- the class type of the object- Returns:
- the JSON bytes encoded using UTF-8
-
serializeListToBytes
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 stringnull. The item type determines the serializer used for each list item and may be a supertype ofT.- Type Parameters:
T- the type of each list item- Parameters:
values- the list to serialize, this parameter may benullitemType- the type to use for serializing each list item- Returns:
- the JSON bytes encoded using UTF-8
-
serializeToBytes
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 stringnull.- Type Parameters:
T- the type of the object- Parameters:
obj- the object to serialize, this parameter may benulltype- the generic type of the object- Returns:
- the JSON bytes encoded using UTF-8
-
serialize
Serializes an object to JSON and writes it to an OutputStream. If the provided object is null, writes the bytes of the stringnullto the output stream.- Parameters:
outputStream- the output stream to write toobj- the object to serialize, this parameter may benull
-
serialize
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 stringnullto the output stream.- Type Parameters:
T- the type of the object- Parameters:
outputStream- the output stream to write toobj- the object to serialize, this parameter may benulltype- 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 stringnullto the output stream. The item type determines the serializer used for each list item and may be a supertype ofT.- Type Parameters:
T- the type of each list item- Parameters:
outputStream- the output stream to write tovalues- the list to serialize, this parameter may benullitemType- the type to use for serializing each list item
-
serialize
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 stringnullto the output stream.- Type Parameters:
T- the type of the object- Parameters:
outputStream- the output stream to write toobj- the object to serialize, this parameter may benulltype- the generic type of the object
-
serialize
Serializes an object to JSON using the provided generator. If the provided object is null, writesnullto the generator.- Parameters:
generator- the JSON generator to write toobj- the object to serialize, this parameter may benull
-
serialize
Serializes an object of a specific type to JSON using the provided generator. If the provided object is null, writesnullto the generator.- Type Parameters:
T- the type of the object- Parameters:
generator- the JSON generator to write toobj- the object to serialize, this parameter may benulltype- the class type of the object
-
serializeList
Serializes a list of objects of a specific item type to JSON using the provided generator. If the provided list is null, writesnullto the generator. The item type determines the serializer used for each list item and may be a supertype ofT.- Type Parameters:
T- the type of each list item- Parameters:
generator- the JSON generator to write tovalues- the list to serialize, this parameter may benullitemType- the type to use for serializing each list item
-
serialize
Serializes an object of a generic type to JSON using the provided generator. If the provided object is null, writesnullto the generator.- Type Parameters:
T- the type of the object- Parameters:
generator- the JSON generator to write toobj- the object to serialize, this parameter may benulltype- the generic type of the object
-
serialize
-
serialize
Serializes an object of a specific type to JSON and writes it to a Writer. If the provided object is null, writes the characters ofnullto the writer.- Type Parameters:
T- the type of the object- Parameters:
writer- the writer to write toobj- the object to serialize, this parameter may benulltype- the class type of the object
-
serializeList
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 ofnullto the writer. The item type determines the serializer used for each list item and may be a supertype ofT.- Type Parameters:
T- the type of each list item- Parameters:
writer- the writer to write tovalues- the list to serialize, this parameter may benullitemType- the type to use for serializing each list item
-
serialize
Serializes an object of a generic type to JSON and writes it to a Writer. If the provided object is null, writes the characters ofnullto the writer.- Type Parameters:
T- the type of the object- Parameters:
writer- the writer to write toobj- the object to serialize, this parameter may benulltype- the generic type of the object
-
deserialize
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 bytestype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 bytesitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 bytestype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
Deserializes JSON from a string to an object of the specified type.- Type Parameters:
T- the type of the object- Parameters:
jsonStr- the JSON stringtype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 stringitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 stringtype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 dataitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
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 databufferSize- the buffer size for readingtype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 databufferSize- the buffer size for readingitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 databufferSize- the buffer size for readingtype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 dataitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
Deserializes a JsonValue to an object of the specified type.- Type Parameters:
T- the type of the object- Parameters:
jsonValue- the JsonValue to deserializetype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 deserializeitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
Deserializes a JsonValue to an object of the specified generic type.- Type Parameters:
T- the type of the object- Parameters:
jsonValue- the JsonValue to deserializetype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the class type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-
deserializeList
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 dataitemType- the class type of each list item- Returns:
- the deserialized list, or
nullwhen the input represents JSON null
-
deserialize
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 datatype- the generic type to deserialize to- Returns:
- the deserialized object, or
nullwhen the input represents JSON null
-