Package io.micronaut.serde
Interface ObjectMapper
- All Superinterfaces:
io.micronaut.json.JsonMapper
- All Known Subinterfaces:
ObjectMapper.CloseableObjectMapper
- All Known Implementing Classes:
AbstractBsonMapper,BsonBinaryMapper,BsonJsonMapper,JacksonJsonMapper,JsonStreamMapper,OracleJdbcJsonBinaryObjectMapper,OracleJdbcJsonTextObjectMapper
public interface ObjectMapper
extends io.micronaut.json.JsonMapper
Sub-interface of
JsonMapper with customizations.- Author:
- graemerocher
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA closeable object mapper. -
Method Summary
Modifier and TypeMethodDescriptiondefault 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 <T> TRead a value from the byte array for the given type.default <T> TreadValue(InputStream inputStream, Class<T> type) Read a value from the given input stream for the given type.default <T> TRead a value from the given string for the given type.default <T> StringwriteValueAsString(io.micronaut.core.type.Argument<T> type, T object) Write the given value as a string.default <T> StringwriteValueAsString(io.micronaut.core.type.Argument<T> type, T object, Charset charset) Write the given value as a string.default <T> StringwriteValueAsString(T object) Write the given value as a string.Methods inherited from interface io.micronaut.json.JsonMapper
cloneWithViewClass, createReactiveParser, detectFeatures, getStreamConfig, readValue, readValue, readValue, readValue, readValueFromTree, readValueFromTree, updateValueFromTree, writeValue, writeValue, writeValueAsBytes, writeValueAsBytes, writeValueToTree, writeValueToTree
-
Method Details
-
readValue
@Nullable default <T> T readValue(@NonNull InputStream inputStream, @NonNull Class<T> type) throws IOException Read a value from the given input stream for the given type.- Type Parameters:
T- The generic type- Parameters:
inputStream- The input streamtype- The type- Returns:
- The value or
nullif it decodes to null - Throws:
IOException- If an unrecoverable error occurs
-
readValue
@Nullable default <T> T readValue(@NonNull byte[] byteArray, @NonNull Class<T> type) throws IOException Read a value from the byte array for the given type.- Type Parameters:
T- The generic type- Parameters:
byteArray- The byte arraytype- The type- Returns:
- The value or
nullif it decodes to null - Throws:
IOException- If an unrecoverable error occurs
-
readValue
@Nullable default <T> T readValue(@NonNull String string, @NonNull Class<T> type) throws IOException Read a value from the given string for the given type.- Type Parameters:
T- The generic type- Parameters:
string- The stringtype- The type- Returns:
- The value or
nullif it decodes to null - Throws:
IOException- If an unrecoverable error occurs
-
writeValueAsString
Write the given value as a string.- Type Parameters:
T- The generic type- Parameters:
object- The object- Returns:
- The string
- Throws:
IOException- If an unrecoverable error occurs
-
cloneWithFeatures
default io.micronaut.json.JsonMapper cloneWithFeatures(io.micronaut.json.JsonFeatures features) - Specified by:
cloneWithFeaturesin interfaceio.micronaut.json.JsonMapper
-
writeValueAsString
@NonNull default <T> String writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object) throws IOException Write the given value as a string.- Type Parameters:
T- The generic type- Parameters:
type- The type, nevernullobject- The object- Returns:
- The string
- Throws:
IOException- If an unrecoverable error occurs
-
writeValueAsString
@NonNull default <T> String writeValueAsString(@NonNull io.micronaut.core.type.Argument<T> type, @Nullable T object, Charset charset) throws IOException Write the given value as a string.- Type Parameters:
T- The generic type- Parameters:
type- The type, nevernullobject- The objectcharset- The charset, nevernull- Returns:
- The string
- Throws:
IOException- If an unrecoverable error occurs
-
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
@NonNull 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
-