public interface ObjectMapper
extends io.micronaut.json.JsonMapper
JsonMapper with customizations.| Modifier and Type | Interface and Description |
|---|---|
static interface |
ObjectMapper.CloseableObjectMapper
A closeable object mapper.
|
| Modifier and Type | Method and Description |
|---|---|
default io.micronaut.json.JsonMapper |
cloneWithFeatures(io.micronaut.json.JsonFeatures features) |
static ObjectMapper.CloseableObjectMapper |
create(java.util.Map<java.lang.String,java.lang.Object> configuration,
java.lang.String... packageNames)
Creates a new custom
ObjectMapper with additional beans (serializers, deserializers etc.) loaded
from the given package locations. |
static ObjectMapper |
getDefault()
Get the default ObjectMapper instance.
|
default <T> T |
readValue(byte[] byteArray,
java.lang.Class<T> type)
Read a value from the byte array for the given type.
|
default <T> T |
readValue(java.io.InputStream inputStream,
java.lang.Class<T> type)
Read a value from the given input stream for the given type.
|
default <T> T |
readValue(java.lang.String string,
java.lang.Class<T> type)
Read a value from the given string for the given type.
|
default <T> java.lang.String |
writeValueAsString(io.micronaut.core.type.Argument<T> type,
T object)
Write the given value as a string.
|
default <T> java.lang.String |
writeValueAsString(io.micronaut.core.type.Argument<T> type,
T object,
java.nio.charset.Charset charset)
Write the given value as a string.
|
default <T> java.lang.String |
writeValueAsString(T object)
Write the given value as a string.
|
cloneWithViewClass, createReactiveParser, detectFeatures, getStreamConfig, readValue, readValue, readValue, readValueFromTree, readValueFromTree, updateValueFromTree, writeValue, writeValue, writeValueAsBytes, writeValueAsBytes, writeValueToTree, writeValueToTree@Nullable
default <T> T readValue(@NonNull
java.io.InputStream inputStream,
@NonNull
java.lang.Class<T> type)
throws java.io.IOException
T - The generic typeinputStream - The input streamtype - The typenull if it decodes to nulljava.io.IOException - If an unrecoverable error occurs@Nullable
default <T> T readValue(@NonNull
byte[] byteArray,
@NonNull
java.lang.Class<T> type)
throws java.io.IOException
T - The generic typebyteArray - The byte arraytype - The typenull if it decodes to nulljava.io.IOException - If an unrecoverable error occurs@Nullable
default <T> T readValue(@NonNull
java.lang.String string,
@NonNull
java.lang.Class<T> type)
throws java.io.IOException
T - The generic typestring - The stringtype - The typenull if it decodes to nulljava.io.IOException - If an unrecoverable error occurs@NonNull
default <T> java.lang.String writeValueAsString(@NonNull
T object)
throws java.io.IOException
T - The generic typeobject - The objectjava.io.IOException - If an unrecoverable error occursdefault io.micronaut.json.JsonMapper cloneWithFeatures(io.micronaut.json.JsonFeatures features)
cloneWithFeatures in interface io.micronaut.json.JsonMapper@NonNull
default <T> java.lang.String writeValueAsString(@NonNull
io.micronaut.core.type.Argument<T> type,
@Nullable
T object)
throws java.io.IOException
T - The generic typetype - The type, never nullobject - The objectjava.io.IOException - If an unrecoverable error occurs@NonNull
default <T> java.lang.String writeValueAsString(@NonNull
io.micronaut.core.type.Argument<T> type,
@Nullable
T object,
java.nio.charset.Charset charset)
throws java.io.IOException
T - The generic typetype - The type, never nullobject - The objectcharset - The charset, never nulljava.io.IOException - If an unrecoverable error occurs@NonNull static ObjectMapper getDefault()
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.
@NonNull static ObjectMapper.CloseableObjectMapper create(java.util.Map<java.lang.String,java.lang.Object> configuration, java.lang.String... packageNames)
ObjectMapper with additional beans (serializers, deserializers etc.) loaded
from the given package locations.configuration - The configurationpackageNames - The package names