Class XmlObjectMapper

java.lang.Object
io.micronaut.serde.xml.XmlObjectMapper
All Implemented Interfaces:
io.micronaut.json.JsonMapper, ObjectMapper

@Singleton @Named("xml") public final class XmlObjectMapper extends Object implements ObjectMapper
The XmlObjectMapper class provides a concrete implementation of the ObjectMapper interface, utilizing XML serialization and deserialization.
Since:
3.2
Author:
Mousrij Hamza
  • Field Details

  • Constructor Details

    • XmlObjectMapper

      public XmlObjectMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration, @Nullable XmlSerdeConfiguration xmlConfiguration) throws SerdeException
      Constructs an XML object mapper.
      Parameters:
      registry - The serde registry
      serdeConfiguration - The shared serde configuration
      xmlConfiguration - The XML serde configuration
      Throws:
      SerdeException - If the XML output factory cannot apply the configured XML features
  • Method Details

    • readValue

      public <T> T readValue(InputStream inputStream, io.micronaut.core.type.Argument<T> type) throws IOException
      Deserializes an XML stream into an object of the requested type.
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The target type
      Parameters:
      inputStream - The XML input stream
      type - The target type
      Returns:
      The deserialized value
      Throws:
      IOException - If an error occurs reading or decoding XML
    • readValue

      public <T> T readValue(byte[] byteArray, io.micronaut.core.type.Argument<T> type) throws IOException
      Deserializes XML bytes into an object of the requested type.
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The target type
      Parameters:
      byteArray - The XML bytes
      type - The target type
      Returns:
      The deserialized value
      Throws:
      IOException - If an error occurs reading or decoding XML
    • readValue

      public <T> T readValue(String string, io.micronaut.core.type.Argument<T> type) throws IOException
      Deserializes an XML string into an object of the requested type.
      Specified by:
      readValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The target type
      Parameters:
      string - The XML string
      type - The target type
      Returns:
      The deserialized value
      Throws:
      IOException - If an error occurs reading or decoding XML
    • readValueFromTree

      public <T> T readValueFromTree(io.micronaut.json.tree.JsonNode tree, io.micronaut.core.type.Argument<T> type) throws IOException
      Deserializes a JSON tree into an object of the requested type.
      Specified by:
      readValueFromTree in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The target type
      Parameters:
      tree - The source tree
      type - The target type
      Returns:
      The deserialized value
      Throws:
      IOException - If an error occurs decoding the tree
    • writeValueToTree

      public io.micronaut.json.tree.JsonNode writeValueToTree(@Nullable Object value) throws IOException
      Serializes a value into a JSON tree.
      Specified by:
      writeValueToTree in interface io.micronaut.json.JsonMapper
      Parameters:
      value - The value to serialize
      Returns:
      The serialized tree
      Throws:
      IOException - If an error occurs serializing the value
    • writeValueToTree

      public <T> io.micronaut.json.tree.JsonNode writeValueToTree(io.micronaut.core.type.Argument<T> type, @Nullable T value) throws IOException
      Serializes a typed value into a JSON tree.
      Specified by:
      writeValueToTree in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The value type
      Parameters:
      type - The value type
      value - The value to serialize
      Returns:
      The serialized tree
      Throws:
      IOException - If an error occurs serializing the value
    • writeValue

      public void writeValue(OutputStream outputStream, @Nullable Object object) throws IOException
      Serializes a value as XML into an output stream.
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Parameters:
      outputStream - The destination output stream
      object - The value to serialize
      Throws:
      IOException - If an error occurs writing or encoding XML
    • writeValue

      public <T> void writeValue(OutputStream outputStream, io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Serializes a typed value as XML into an output stream.
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The value type
      Parameters:
      outputStream - The destination output stream
      type - The value type
      object - The value to serialize
      Throws:
      IOException - If an error occurs writing or encoding XML
    • writeValueAsBytes

      public byte[] writeValueAsBytes(@Nullable Object object) throws IOException
      Serializes a value as XML bytes.
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Parameters:
      object - The value to serialize
      Returns:
      The serialized XML bytes
      Throws:
      IOException - If an error occurs writing or encoding XML
    • writeValueAsBytes

      public <T> byte[] writeValueAsBytes(io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Serializes a typed value as XML bytes.
      Specified by:
      writeValueAsBytes in interface io.micronaut.json.JsonMapper
      Type Parameters:
      T - The value type
      Parameters:
      type - The value type
      object - The value to serialize
      Returns:
      The serialized XML bytes
      Throws:
      IOException - If an error occurs writing or encoding XML
    • writeValueAsString

      public String writeValueAsString(@Nullable Object object) throws IOException
      Serializes a value as an XML string.
      Specified by:
      writeValueAsString in interface io.micronaut.json.JsonMapper
      Parameters:
      object - The value to serialize
      Returns:
      The serialized XML string
      Throws:
      IOException - If an error occurs writing or encoding XML
    • getStreamConfig

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