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 interface
A closeable object mapper. -
Method Summary
Modifier and TypeMethodDescriptiondefault io.micronaut.json.JsonMapper
cloneWithFeatures
(io.micronaut.json.JsonFeatures features) Creates a new customObjectMapper
with additional beans (serializers, deserializers etc.) loaded from the given package locations.static ObjectMapper
Get the default ObjectMapper instance.default <T> T
Read a value from the byte array for the given type.default <T> T
readValue
(InputStream inputStream, Class<T> type) Read a value from the given input stream for the given type.default <T> T
Read a value from the given string for the given type.default <T> String
writeValueAsString
(io.micronaut.core.type.Argument<T> type, T object) Write the given value as a string.default <T> String
writeValueAsString
(io.micronaut.core.type.Argument<T> type, T object, Charset charset) Write the given value as a string.default <T> String
writeValueAsString
(T object) Write the given value as a string.Methods inherited from interface io.micronaut.json.JsonMapper
cloneWithViewClass, createReactiveParser, createSpecific, 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
null
if 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
null
if 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
null
if 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:
cloneWithFeatures
in 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, nevernull
object
- 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, nevernull
object
- 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 customObjectMapper
with 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
-