Class TomlObjectMapper
java.lang.Object
io.micronaut.serde.toml.TomlObjectMapper
- All Implemented Interfaces:
io.micronaut.json.JsonMapper, io.micronaut.serde.ObjectMapper
@Singleton
@Named("toml")
@Internal
public final class TomlObjectMapper
extends Object
implements io.micronaut.serde.ObjectMapper
A TOML-backed
ObjectMapper.
The serialization output style is controlled by
SerdeTomlConfiguration.WriteFeatures.getWriteLayout()
(micronaut.serde.toml.write-features.write-layout):
Reads are guarded by SerdeTomlConfiguration.ReadConstraints
(micronaut.serde.toml.read-constraints.*) — maximum document size, string-value length and
number-token length — together with the serde nesting-depth limit.
- Since:
- 3.0.1
- Author:
- Mousrij Hamza
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.micronaut.serde.ObjectMapper
io.micronaut.serde.ObjectMapper.CloseableObjectMapper -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTomlObjectMapper(io.micronaut.serde.SerdeRegistry registry, io.micronaut.serde.config.SerdeConfiguration serdeConfiguration, SerdeTomlConfiguration tomlConfiguration) Creates a TOML-backedObjectMapper. -
Method Summary
Modifier and TypeMethodDescription@NonNull io.micronaut.serde.SerdeRegistryReturns theSerdeRegistryused by this object mapper, if possible.@NonNull io.micronaut.json.JsonStreamConfig<T> @Nullable TreadValue(byte @NonNull [] byteArray, @NonNull io.micronaut.core.type.Argument<T> type) Parse and map Toml from the given byte array.<T> @Nullable TreadValue(@NonNull InputStream inputStream, @NonNull io.micronaut.core.type.Argument<T> type) Parse and map Toml from the given stream.<T> @Nullable TreadValueFromTree(@NonNull io.micronaut.json.tree.JsonNode tree, @NonNull io.micronaut.core.type.Argument<T> type) Transform aJsonNodeto a value of the given type.<T> voidwriteValue(@NonNull OutputStream outputStream, @NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) Write an object as Toml using JsonNode entities.voidwriteValue(@NonNull OutputStream outputStream, @Nullable Object object) Write an object as Toml using JsonNode entities.<T> byte @NonNull []writeValueAsBytes(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) Write an object as Toml using JsonNode entities.byte @NonNull []writeValueAsBytes(@Nullable Object object) Write an object as Toml using JsonNode entities.<T> @NonNull io.micronaut.json.tree.JsonNodewriteValueToTree(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T value) Transform an object value to a json tree.@NonNull io.micronaut.json.tree.JsonNodewriteValueToTree(@Nullable Object value) Transform an object value to a json tree.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.micronaut.json.JsonMapper
cloneWithViewClass, createReactiveParser, createSpecific, detectFeatures, readValue, readValue, readValue, readValue, readValue, readValue, readValueFromTree, updateValueFromTree, writeValueAsString, writeValueAsString, writeValueAsStringMethods inherited from interface io.micronaut.serde.ObjectMapper
cloneWithConfiguration, cloneWithConfiguration, cloneWithFeatures, updateValue, updateValue, updateValue, updateValue, updateValue
-
Field Details
-
NAME
-
-
Constructor Details
-
TomlObjectMapper
public TomlObjectMapper(io.micronaut.serde.SerdeRegistry registry, io.micronaut.serde.config.SerdeConfiguration serdeConfiguration, SerdeTomlConfiguration tomlConfiguration) Creates a TOML-backedObjectMapper.- Parameters:
registry- The serde registryserdeConfiguration- The serde configurationtomlConfiguration- The TOML-specific configuration
-
-
Method Details
-
getSerdeRegistry
public @NonNull io.micronaut.serde.SerdeRegistry getSerdeRegistry()Returns theSerdeRegistryused by this object mapper, if possible.- Specified by:
getSerdeRegistryin interfaceio.micronaut.serde.ObjectMapper- Returns:
- The serde registry
-
readValue
public <T> @Nullable T readValue(@NonNull InputStream inputStream, @NonNull io.micronaut.core.type.Argument<T> type) throws IOException Parse and map Toml from the given stream.- Specified by:
readValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- Type variable of the return type.- Parameters:
inputStream- The input data.type- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException- IOException
-
readValue
public <T> @Nullable T readValue(byte @NonNull [] byteArray, @NonNull io.micronaut.core.type.Argument<T> type) throws IOException Parse and map Toml from the given byte array.- Specified by:
readValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- Type variable of the return type.- Parameters:
byteArray- The input data.type- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException- IOException
-
readValueFromTree
public <T> @Nullable T readValueFromTree(@NonNull io.micronaut.json.tree.JsonNode tree, @NonNull io.micronaut.core.type.Argument<T> type) throws IOException Transform aJsonNodeto a value of the given type.- Specified by:
readValueFromTreein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- Type variable of the return type.- Parameters:
tree- The input json data.type- The type to deserialize.- Returns:
- The deserialized value.
- Throws:
IOException- IOException
-
writeValueToTree
public @NonNull io.micronaut.json.tree.JsonNode writeValueToTree(@Nullable Object value) throws IOException Transform an object value to a json tree.- Specified by:
writeValueToTreein interfaceio.micronaut.json.JsonMapper- Parameters:
value- The object value to transform.- Returns:
- The json representation.
- Throws:
IOException- If there are any mapping exceptions (e.g. illegal values).
-
writeValueToTree
public <T> @NonNull io.micronaut.json.tree.JsonNode writeValueToTree(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T value) throws IOException Transform an object value to a json tree.- Specified by:
writeValueToTreein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The type variable of the type.- Parameters:
type- The object typevalue- The object value to transform.- Returns:
- The json representation.
- Throws:
IOException- If there are any mapping exceptions (e.g. illegal values).
-
writeValue
public void writeValue(@NonNull OutputStream outputStream, @Nullable Object object) throws IOException Write an object as Toml using JsonNode entities.- Specified by:
writeValuein interfaceio.micronaut.json.JsonMapper- Parameters:
outputStream- The stream to write to.object- The object to serialize.- Throws:
IOException- IOException
-
writeValue
public <T> void writeValue(@NonNull OutputStream outputStream, @NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException Write an object as Toml using JsonNode entities.- Specified by:
writeValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The generic type- Parameters:
outputStream- The stream to write to.type- The object typeobject- The object to serialize.- Throws:
IOException- IOException
-
writeValueAsBytes
Write an object as Toml using JsonNode entities.- Specified by:
writeValueAsBytesin interfaceio.micronaut.json.JsonMapper- Parameters:
object- The object to serialize.- Returns:
- The serialized encoded json.
- Throws:
IOException- IOException
-
writeValueAsBytes
public <T> byte @NonNull [] writeValueAsBytes(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException Write an object as Toml using JsonNode entities.- Specified by:
writeValueAsBytesin interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The generic type- Parameters:
type- The object typeobject- The object to serialize.- Returns:
- The serialized encoded json.
- Throws:
IOException- IOException
-
getStreamConfig
public @NonNull io.micronaut.json.JsonStreamConfig getStreamConfig()- Specified by:
getStreamConfigin interfaceio.micronaut.json.JsonMapper- Returns:
- The configured stream config.
-