Class PropertiesMapper

java.lang.Object
io.micronaut.serde.properties.PropertiesMapper
All Implemented Interfaces:
io.micronaut.json.JsonMapper, ObjectMapper

@Singleton @Secondary @Named("properties") public final class PropertiesMapper extends Object implements ObjectMapper
A Java .properties-backed ObjectMapper.

Reads and parses flat .properties documents into an intermediate JsonNode tree before delegating to Micronaut Serialization.

Serializes values to a JsonNode tree first, then flattens object paths and array indexes into .properties key/value lines. Array index syntax is controlled by SerdePropertiesConfiguration; the default is bracketed indexes.

Since:
3.1.0
Author:
Mousrij Hamza
  • Field Details

  • Constructor Details

    • PropertiesMapper

      @Inject public PropertiesMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration, PropertiesTreeAdapter propertiesTreeAdapter, PropertiesWriter propertiesWriter, JsonStreamMapper jsonStreamMapper)
      Creates a Java .properties-backed ObjectMapper.
      Parameters:
      registry - The serde registry used to resolve serializers and deserializers
      serdeConfiguration - The serde configuration, when available
      propertiesTreeAdapter - The adapter that converts properties input into a JSON tree
      propertiesWriter - The writer that flattens JSON trees into properties output
      jsonStreamMapper - The JSON stream mapper used for intermediary tree conversion
  • 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
    • 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 .properties 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 properties input stream
      type - The target type
      Returns:
      The deserialized object
      Throws:
      IOException - If the properties input cannot be read
    • readValue

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

      @NonNull 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 .properties data.
      Specified by:
      writeValue in interface io.micronaut.json.JsonMapper
      Parameters:
      outputStream - The destination stream
      object - The object to serialize
      Throws:
      IOException - If writing the properties 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 .properties data.
      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 properties output fails
    • writeValueAsBytes

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

      public <T> byte[] writeValueAsBytes(io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException
      Write an object as .properties data.
      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 .properties bytes
      Throws:
      IOException - If writing the properties output fails
    • 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