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):

  • TABLE (default) as [table] headers
  • INLINE — as inline tables, e.g. key = {a = 1, b = 2}.

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
    Modifier and Type
    Field
    Description
    static final String
    The qualifier name of the TOML ObjectMapper bean.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TomlObjectMapper(io.micronaut.serde.SerdeRegistry registry, io.micronaut.serde.config.SerdeConfiguration serdeConfiguration, SerdeTomlConfiguration tomlConfiguration)
    Creates a TOML-backed ObjectMapper.
  • Method Summary

    Modifier and Type
    Method
    Description
    @NonNull io.micronaut.serde.SerdeRegistry
    Returns the SerdeRegistry used by this object mapper, if possible.
    @NonNull io.micronaut.json.JsonStreamConfig
     
    <T> @Nullable T
    readValue(byte @NonNull [] byteArray, @NonNull io.micronaut.core.type.Argument<T> type)
    Parse and map Toml from the given byte array.
    <T> @Nullable T
    readValue(@NonNull InputStream inputStream, @NonNull io.micronaut.core.type.Argument<T> type)
    Parse and map Toml from the given stream.
    <T> @Nullable T
    readValueFromTree(@NonNull io.micronaut.json.tree.JsonNode tree, @NonNull io.micronaut.core.type.Argument<T> type)
    Transform a JsonNode to a value of the given type.
    <T> void
    writeValue(@NonNull OutputStream outputStream, @NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object)
    Write an object as Toml using JsonNode entities.
    void
    writeValue(@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.JsonNode
    writeValueToTree(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T value)
    Transform an object value to a json tree.
    @NonNull io.micronaut.json.tree.JsonNode
    writeValueToTree(@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, wait

    Methods inherited from interface io.micronaut.json.JsonMapper

    cloneWithViewClass, createReactiveParser, createSpecific, detectFeatures, readValue, readValue, readValue, readValue, readValue, readValue, readValueFromTree, updateValueFromTree, writeValueAsString, writeValueAsString, writeValueAsString

    Methods inherited from interface io.micronaut.serde.ObjectMapper

    cloneWithConfiguration, cloneWithConfiguration, cloneWithFeatures, updateValue, updateValue, updateValue, updateValue, updateValue
  • Field Details

  • Constructor Details

    • TomlObjectMapper

      public TomlObjectMapper(io.micronaut.serde.SerdeRegistry registry, io.micronaut.serde.config.SerdeConfiguration serdeConfiguration, SerdeTomlConfiguration tomlConfiguration)
      Creates a TOML-backed ObjectMapper.
      Parameters:
      registry - The serde registry
      serdeConfiguration - The serde configuration
      tomlConfiguration - The TOML-specific configuration
  • Method Details

    • getSerdeRegistry

      public @NonNull io.micronaut.serde.SerdeRegistry getSerdeRegistry()
      Returns the SerdeRegistry used by this object mapper, if possible.
      Specified by:
      getSerdeRegistry in interface io.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:
      readValue in interface io.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:
      readValue in interface io.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 a JsonNode to a value of the given type.
      Specified by:
      readValueFromTree in interface io.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:
      writeValueToTree in interface io.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:
      writeValueToTree in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The type variable of the type.
      Parameters:
      type - The object type
      value - 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:
      writeValue in interface io.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:
      writeValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The generic type
      Parameters:
      outputStream - The stream to write to.
      type - The object type
      object - The object to serialize.
      Throws:
      IOException - IOException
    • writeValueAsBytes

      public byte @NonNull [] writeValueAsBytes(@Nullable Object object) throws IOException
      Write an object as Toml using JsonNode entities.
      Specified by:
      writeValueAsBytes in interface io.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:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The generic type
      Parameters:
      type - The object type
      object - The object to serialize.
      Returns:
      The serialized encoded json.
      Throws:
      IOException - IOException
    • getStreamConfig

      public @NonNull io.micronaut.json.JsonStreamConfig getStreamConfig()
      Specified by:
      getStreamConfig in interface io.micronaut.json.JsonMapper
      Returns:
      The configured stream config.