Class ToonMapper

java.lang.Object
io.micronaut.serde.toon.ToonMapper
All Implemented Interfaces:
io.micronaut.json.JsonMapper, ObjectMapper

@Singleton @Secondary @Named("toon") public final class ToonMapper extends Object implements ObjectMapper
A TOON (Token-Oriented Object Notation)-backed ObjectMapper.

Reads a TOON document into a JsonNode tree and deserializes from that tree. Serializes to a JsonNode tree and writes it as a TOON document.

Since:
3.3.0
See Also:
  • Field Details

  • Constructor Details

    • ToonMapper

      @Inject public ToonMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration, ToonDecoder toonDecoder, ToonEncoder toonEncoder, @Nullable Class<?> view)
      Creates a TOON-backed ObjectMapper.
      Parameters:
      registry - The serde registry used to resolve serializers and deserializers
      serdeConfiguration - The serde configuration, when available
      toonDecoder - The decoder that converts TOON input into a JSON tree
      toonEncoder - The encoder that writes JSON trees as TOON output
      view - The active @JsonView class, when available
  • Method Details

    • getSerdeRegistry

      public SerdeRegistry getSerdeRegistry()
      Returns the SerdeRegistry used by this object mapper, if possible.
      Specified by:
      getSerdeRegistry in interface ObjectMapper
      Returns:
      The serde registry
    • cloneWithViewClass

      public io.micronaut.json.JsonMapper cloneWithViewClass(Class<?> viewClass)
      Specified by:
      cloneWithViewClass in interface io.micronaut.json.JsonMapper
    • cloneWithConfiguration

      public ObjectMapper cloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration)
      Description copied from interface: ObjectMapper
      Optional feature. Create a new ObjectMapper with the given configuration values. A null parameter indicates the old configuration should be used.
      Specified by:
      cloneWithConfiguration in interface ObjectMapper
      Parameters:
      configuration - The SerdeConfiguration
      serializationConfiguration - The SerializationConfiguration
      deserializationConfiguration - The DeserializationConfiguration
      Returns:
      A new JsonMapper with the updated config
    • cloneWithConfiguration

      public ObjectMapper cloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration, @Nullable SerdeIntrospections introspections)
      Description copied from interface: ObjectMapper
      Optional feature. Create a new ObjectMapper with the given configuration values and introspections. A null configuration parameter indicates the old configuration should be used.
      Specified by:
      cloneWithConfiguration in interface ObjectMapper
      Parameters:
      configuration - The SerdeConfiguration
      serializationConfiguration - The SerializationConfiguration
      deserializationConfiguration - The DeserializationConfiguration
      introspections - The SerdeIntrospections
      Returns:
      A new JsonMapper with the updated config and introspections
    • readValueFromTree

      public <T> @Nullable T readValueFromTree(io.micronaut.json.tree.JsonNode tree, 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 source tree to deserialize
      type - The target type
      Returns:
      The deserialized value
      Throws:
      IOException - If tree decoding fails
    • readValue

      public <T> @Nullable T readValue(InputStream inputStream, io.micronaut.core.type.Argument<T> type) throws IOException
      Parse and map TOON data 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 TOON input stream
      type - The target type
      Returns:
      The deserialized object
      Throws:
      IOException - If the TOON input cannot be read
    • readValue

      public <T> @Nullable T readValue(byte[] byteArray, io.micronaut.core.type.Argument<T> type) throws IOException
      Parse and map TOON data 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 TOON bytes
      type - The target type
      Returns:
      The deserialized object
      Throws:
      IOException - If the TOON input cannot be read
    • 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 value to convert
      Returns:
      The JSON representation
      Throws:
      IOException - If serialization to the tree fails
    • writeValueToTree

      public <T> io.micronaut.json.tree.JsonNode writeValueToTree(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 declared type of the value
      value - The value to convert
      Returns:
      The JSON representation
      Throws:
      IOException - If serialization to the tree fails
    • writeValue

      public void writeValue(OutputStream outputStream, @Nullable Object object) throws IOException
      Write an object as a TOON document.
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Parameters:
      outputStream - The destination stream
      object - The object to serialize
      Throws:
      IOException - If writing the TOON output fails
    • writeValue

      public <T> void writeValue(OutputStream outputStream, io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Write an object as a TOON document.
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The generic type
      Parameters:
      outputStream - The destination stream
      type - The declared type of the object
      object - The object to serialize
      Throws:
      IOException - If writing the TOON output fails
    • writeValueAsBytes

      public byte[] writeValueAsBytes(@Nullable Object object) throws IOException
      Write an object as a TOON document.
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Parameters:
      object - The object to serialize
      Returns:
      The serialized TOON bytes
      Throws:
      IOException - If writing the TOON output fails
    • writeValueAsBytes

      public <T> byte[] writeValueAsBytes(io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Write an object as a TOON document.
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The generic type
      Parameters:
      type - The declared type of the object
      object - The object to serialize
      Returns:
      The serialized TOON bytes
      Throws:
      IOException - If writing the TOON output fails
    • updateValueFromTree

      public void updateValueFromTree(Object value, io.micronaut.json.tree.JsonNode tree) throws IOException
      Specified by:
      updateValueFromTree in interface io.micronaut.json.JsonMapper
      Throws:
      IOException
    • updateValue

      public <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, InputStream inputStream) throws IOException
      Description copied from interface: ObjectMapper
      Update an existing mutable value from JSON read from the supplied input stream.
      Specified by:
      updateValue in interface ObjectMapper
      Type Parameters:
      T - The value type
      Parameters:
      valueToUpdate - The existing value to update
      type - The type of the value to update
      inputStream - The input stream containing JSON fields to apply
      Returns:
      The updated valueToUpdate
      Throws:
      IOException - If an I/O or decoding error occurs
    • updateValue

      public <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, byte[] byteArray) throws IOException
      Description copied from interface: ObjectMapper
      Update an existing mutable value from JSON read from the supplied byte array.
      Specified by:
      updateValue in interface ObjectMapper
      Type Parameters:
      T - The value type
      Parameters:
      valueToUpdate - The existing value to update
      type - The type of the value to update
      byteArray - The byte array containing JSON fields to apply
      Returns:
      The updated valueToUpdate
      Throws:
      IOException - If an I/O or decoding error occurs
    • getStreamConfig

      public io.micronaut.json.JsonStreamConfig getStreamConfig()
      Returns the stream configuration used by this mapper.
      Specified by:
      getStreamConfig in interface io.micronaut.json.JsonMapper
      Returns:
      The configured stream config