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
-
Nested Class Summary
Nested classes/interfaces inherited from interface ObjectMapper
ObjectMapper.CloseableObjectMapper -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe qualifier name of the.propertiesObjectMapperbean. -
Constructor Summary
ConstructorsConstructorDescriptionPropertiesMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration, PropertiesTreeAdapter propertiesTreeAdapter, PropertiesWriter propertiesWriter, JsonStreamMapper jsonStreamMapper) Creates a Java.properties-backedObjectMapper. -
Method Summary
Modifier and TypeMethodDescriptionReturns theSerdeRegistryused by this object mapper, if possible.io.micronaut.json.JsonStreamConfigReturns the stream configuration used by this mapper.<T> @Nullable TreadValue(byte[] byteArray, io.micronaut.core.type.Argument<T> type) Parse and map.propertiesdata from the given byte array.<T> @Nullable TreadValue(InputStream inputStream, io.micronaut.core.type.Argument<T> type) Parse and map.propertiesdata from the given stream.<T> @Nullable TreadValueFromTree(io.micronaut.json.tree.JsonNode tree, io.micronaut.core.type.Argument<T> type) Transform aJsonNodeto a value of the given type.<T> voidwriteValue(OutputStream outputStream, io.micronaut.core.type.Argument<T> type, @Nullable T object) Write an object as.propertiesdata.voidwriteValue(OutputStream outputStream, @Nullable Object object) Write an object as.propertiesdata.<T> byte[]writeValueAsBytes(io.micronaut.core.type.Argument<T> type, @Nullable T object) Write an object as.propertiesdata.byte[]writeValueAsBytes(@Nullable Object object) Write an object as.propertiesdata.<T> io.micronaut.json.tree.JsonNodewriteValueToTree(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 ObjectMapper
cloneWithConfiguration, cloneWithConfiguration, cloneWithFeatures, updateValue, updateValue, updateValue, updateValue, updateValue
-
Field Details
-
NAME
-
-
Constructor Details
-
PropertiesMapper
@Inject public PropertiesMapper(SerdeRegistry registry, @Nullable SerdeConfiguration serdeConfiguration, PropertiesTreeAdapter propertiesTreeAdapter, PropertiesWriter propertiesWriter, JsonStreamMapper jsonStreamMapper) Creates a Java.properties-backedObjectMapper.- Parameters:
registry- The serde registry used to resolve serializers and deserializersserdeConfiguration- The serde configuration, when availablepropertiesTreeAdapter- The adapter that converts properties input into a JSON treepropertiesWriter- The writer that flattens JSON trees into properties outputjsonStreamMapper- The JSON stream mapper used for intermediary tree conversion
-
-
Method Details
-
getSerdeRegistry
Returns theSerdeRegistryused by this object mapper, if possible.- Specified by:
getSerdeRegistryin interfaceObjectMapper- 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 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 source tree to deserializetype- 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.propertiesdata from the given stream.- Specified by:
readValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- Type variable of the return type- Parameters:
inputStream- The properties input streamtype- 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.propertiesdata from the given byte array.- Specified by:
readValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- Type variable of the return type- Parameters:
byteArray- The properties bytestype- 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:
writeValueToTreein interfaceio.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:
writeValueToTreein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The type variable of the type- Parameters:
type- The declared type of the valuevalue- The value to convert- Returns:
- The JSON representation
- Throws:
IOException- If serialization to the tree fails
-
writeValue
Write an object as.propertiesdata.- Specified by:
writeValuein interfaceio.micronaut.json.JsonMapper- Parameters:
outputStream- The destination streamobject- 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.propertiesdata.- Specified by:
writeValuein interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The generic type- Parameters:
outputStream- The destination streamtype- The declared type of the objectobject- The object to serialize- Throws:
IOException- If writing the properties output fails
-
writeValueAsBytes
Write an object as.propertiesdata.- Specified by:
writeValueAsBytesin interfaceio.micronaut.json.JsonMapper- Parameters:
object- The object to serialize- Returns:
- The serialized
.propertiesbytes - 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.propertiesdata.- Specified by:
writeValueAsBytesin interfaceio.micronaut.json.JsonMapper- Type Parameters:
T- The generic type- Parameters:
type- The declared type of the objectobject- The object to serialize- Returns:
- The serialized
.propertiesbytes - 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:
getStreamConfigin interfaceio.micronaut.json.JsonMapper- Returns:
- The configured stream config
-