Interface ObjectMapper
- All Superinterfaces:
io.micronaut.json.JsonMapper
- All Known Subinterfaces:
JacksonObjectMapper, ObjectMapper.CloseableObjectMapper
- All Known Implementing Classes:
AbstractBsonMapper, BsonBinaryMapper, BsonJsonMapper, JacksonJsonMapper, JsonStreamMapper, OracleJdbcJsonBinaryObjectMapper, OracleJdbcJsonTextObjectMapper, PropertiesMapper
JsonMapper with customizations.- Author:
- graemerocher
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA closeable object mapper. -
Method Summary
Modifier and TypeMethodDescriptiondefault ObjectMappercloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration) Optional feature.default ObjectMappercloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration, SerdeIntrospections introspections) Optional feature.default io.micronaut.json.JsonMappercloneWithFeatures(io.micronaut.json.JsonFeatures features) Creates a new customObjectMapperwith additional beans (serializers, deserializers etc.) loaded from the given package locations.static ObjectMapperGet the default ObjectMapper instance.default SerdeRegistryReturns theSerdeRegistryused by this object mapper, if possible.default <T> TupdateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, byte[] byteArray) Update an existing mutable value from JSON read from the supplied byte array.default <T> TupdateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, io.micronaut.core.io.buffer.ByteBuffer<?> byteBuffer) Update an existing mutable value from JSON read from the supplied byte buffer.default <T> TupdateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, InputStream inputStream) Update an existing mutable value from JSON read from the supplied input stream.default <T> TupdateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, @Nullable Object overrides) Update an existing mutable value from the supplied override value.default <T> TupdateValue(T valueToUpdate, @Nullable Object overrides) Update an existing mutable value from the supplied override value.Methods inherited from interface io.micronaut.json.JsonMapper
cloneWithViewClass, createReactiveParser, createSpecific, detectFeatures, getStreamConfig, readValue, readValue, readValue, readValue, readValue, readValue, readValue, readValue, readValueFromTree, readValueFromTree, updateValueFromTree, writeValue, writeValue, writeValueAsBytes, writeValueAsBytes, writeValueAsString, writeValueAsString, writeValueAsString, writeValueToTree, writeValueToTree
-
Method Details
-
updateValue
Update an existing mutable value from the supplied override value.The override value is converted to a JSON tree and applied through
JsonMapper.updateValueFromTree(Object, JsonNode). Supported update semantics are implementation-specific; immutable, creator-only, and builder-only values may be rejected.- Type Parameters:
T- The value type- Parameters:
valueToUpdate- The existing value to updateoverrides- The override value containing fields to apply- Returns:
- The updated
valueToUpdate - Throws:
IOException- If an I/O or decoding error occurs- Since:
- 3.1
-
updateValue
default <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, @Nullable Object overrides) throws IOException Update an existing mutable value from the supplied override value.The override value is converted to a JSON tree and applied through
JsonMapper.updateValueFromTree(Object, JsonNode). Supported update semantics are implementation-specific; immutable, creator-only, and builder-only values may be rejected.- Type Parameters:
T- The value type- Parameters:
valueToUpdate- The existing value to updatetype- The type of the value to updateoverrides- The override value containing fields to apply- Returns:
- The updated
valueToUpdate - Throws:
IOException- If an I/O or decoding error occurs- Since:
- 3.1
-
updateValue
default <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, InputStream inputStream) throws IOException Update an existing mutable value from JSON read from the supplied input stream.- Type Parameters:
T- The value type- Parameters:
valueToUpdate- The existing value to updatetype- The type of the value to updateinputStream- The input stream containing JSON fields to apply- Returns:
- The updated
valueToUpdate - Throws:
IOException- If an I/O or decoding error occurs- Since:
- 3.1
-
updateValue
default <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, byte[] byteArray) throws IOException Update an existing mutable value from JSON read from the supplied byte array.- Type Parameters:
T- The value type- Parameters:
valueToUpdate- The existing value to updatetype- The type of the value to updatebyteArray- The byte array containing JSON fields to apply- Returns:
- The updated
valueToUpdate - Throws:
IOException- If an I/O or decoding error occurs- Since:
- 3.1
-
updateValue
default <T> T updateValue(T valueToUpdate, io.micronaut.core.type.Argument<T> type, io.micronaut.core.io.buffer.ByteBuffer<?> byteBuffer) throws IOException Update an existing mutable value from JSON read from the supplied byte buffer.- Type Parameters:
T- The value type- Parameters:
valueToUpdate- The existing value to updatetype- The type of the value to updatebyteBuffer- The byte buffer containing JSON fields to apply- Returns:
- The updated
valueToUpdate - Throws:
IOException- If an I/O or decoding error occurs- Since:
- 3.1
-
cloneWithFeatures
default io.micronaut.json.JsonMapper cloneWithFeatures(io.micronaut.json.JsonFeatures features) - Specified by:
cloneWithFeaturesin interfaceio.micronaut.json.JsonMapper
-
cloneWithConfiguration
default ObjectMapper cloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration) Optional feature. Create a newObjectMapperwith the given configuration values. Anullparameter indicates the old configuration should be used.- Parameters:
configuration- TheSerdeConfigurationserializationConfiguration- TheSerializationConfigurationdeserializationConfiguration- TheDeserializationConfiguration- Returns:
- A new
JsonMapperwith the updated config - Since:
- 2.7.0
-
cloneWithConfiguration
default ObjectMapper cloneWithConfiguration(@Nullable SerdeConfiguration configuration, @Nullable SerializationConfiguration serializationConfiguration, @Nullable DeserializationConfiguration deserializationConfiguration, SerdeIntrospections introspections) Optional feature. Create a newObjectMapperwith the given configuration values and introspections. Anullconfiguration parameter indicates the old configuration should be used.- Parameters:
configuration- TheSerdeConfigurationserializationConfiguration- TheSerializationConfigurationdeserializationConfiguration- TheDeserializationConfigurationintrospections- TheSerdeIntrospections- Returns:
- A new
JsonMapperwith the updated config and introspections - Since:
- 3.1.0
-
getSerdeRegistry
Returns theSerdeRegistryused by this object mapper, if possible.- Returns:
- The serde registry
-
getDefault
Get the default ObjectMapper instance.Note that this method returns an ObjectMapper that does not include any custom defined serializers or deserializers and in general should be avoided outside a few niche cases that require static access.
Where possible you should use dependency injection to instead retrieve the ObjectMapper from the application context.
- Returns:
- The default object mapper
- Since:
- 1.3.0
-
create
static ObjectMapper.CloseableObjectMapper create(Map<String, Object> configuration, String... packageNames) Creates a new customObjectMapperwith additional beans (serializers, deserializers etc.) loaded from the given package locations.- Parameters:
configuration- The configurationpackageNames- The package names- Returns:
- The new object mapper
- Since:
- 1.5.1
-