Package io.micronaut.jackson.databind
Class JacksonDatabindMapper
java.lang.Object
io.micronaut.jackson.databind.JacksonDatabindMapper
- All Implemented Interfaces:
JsonMapper
jackson-databind implementation of
JsonMapper
.- Since:
- 3.1
- Author:
- Jonas Konrad
-
Constructor Summary
ConstructorDescriptionJacksonDatabindMapper
(com.fasterxml.jackson.databind.ObjectMapper objectMapper) -
Method Summary
Modifier and TypeMethodDescriptioncloneWithFeatures
(@NonNull JsonFeatures features) Create a copy of this mapper with the given json features as returned byJsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata)
.cloneWithViewClass
(@NonNull Class<?> viewClass) Create a copy of this mapper with the given view class.createReactiveParser
(@NonNull Consumer<Processor<byte[], JsonNode>> onSubscribe, boolean streamArray) createSpecific
(Argument<?> type) Specialize this mapper for the given type.detectFeatures
(@NonNull AnnotationMetadata annotations) DetectJsonFeatures
from the given annotation data.com.fasterxml.jackson.databind.ObjectMapper
<T> T
Parse and map json from the given byte array.<T> T
readValue
(@NonNull InputStream inputStream, @NonNull Argument<T> type) Parse and map json from the given stream.<T> T
readValue
(ByteBuffer<?> byteBuffer, Argument<T> type) Parse and map json from the given byte buffer.<T> T
readValueFromTree
(@NonNull JsonNode tree, @NonNull Argument<T> type) Transform aJsonNode
to a value of the given type.void
updateValueFromTree
(Object value, @NonNull JsonNode tree) Update an object from json data.<T> void
writeValue
(@NonNull OutputStream outputStream, @NonNull Argument<T> type, T object) Write an object as json.void
writeValue
(@NonNull OutputStream outputStream, @Nullable Object object) Write an object as json.<T> byte[]
writeValueAsBytes
(@NonNull Argument<T> type, T object) Write an object as json.byte[]
writeValueAsBytes
(@Nullable Object object) Write an object as json.writeValueToTree
(@NonNull Argument<T> type, T value) Transform an object value to a json tree.writeValueToTree
(@Nullable Object value) Transform an object value to a json tree.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.micronaut.json.JsonMapper
readValue, readValue, readValue, readValue, readValueFromTree, writeValueAsString, writeValueAsString, writeValueAsString
-
Constructor Details
-
JacksonDatabindMapper
-
JacksonDatabindMapper
-
-
Method Details
-
getObjectMapper
-
createSpecific
Description copied from interface:JsonMapper
Specialize this mapper for the given type. Read and write operations on the returned mapper may only be called with that type.- Specified by:
createSpecific
in interfaceJsonMapper
- Parameters:
type
- The type to read or write- Returns:
- The specialized
JsonMapper
.
-
readValueFromTree
public <T> T readValueFromTree(@NonNull @NonNull JsonNode tree, @NonNull @NonNull Argument<T> type) throws IOException Description copied from interface:JsonMapper
Transform aJsonNode
to a value of the given type.- Specified by:
readValueFromTree
in interfaceJsonMapper
- Type Parameters:
T
- Type variable of the return type.- Parameters:
tree
- The input json data.type
- The type to deserialize.- Returns:
- The deserialized value.
- Throws:
IOException
- IOException
-
writeValueToTree
@NonNull public @NonNull JsonNode writeValueToTree(@Nullable @Nullable Object value) throws IOException Description copied from interface:JsonMapper
Transform an object value to a json tree.- Specified by:
writeValueToTree
in interfaceJsonMapper
- Parameters:
value
- The object value to transform.- Returns:
- The json representation.
- Throws:
IOException
- If there are any mapping exceptions (e.g. illegal values).
-
writeValueToTree
@NonNull public <T> @NonNull JsonNode writeValueToTree(@NonNull @NonNull Argument<T> type, T value) throws IOException Description copied from interface:JsonMapper
Transform an object value to a json tree.- Specified by:
writeValueToTree
in interfaceJsonMapper
- Type Parameters:
T
- The type variable of the type.- Parameters:
type
- The object typevalue
- The object value to transform.- Returns:
- The json representation.
- Throws:
IOException
- If there are any mapping exceptions (e.g. illegal values).
-
readValue
public <T> T readValue(@NonNull @NonNull InputStream inputStream, @NonNull @NonNull Argument<T> type) throws IOException Description copied from interface:JsonMapper
Parse and map json from the given stream.- Specified by:
readValue
in interfaceJsonMapper
- Type Parameters:
T
- Type variable of the return type.- Parameters:
inputStream
- The input data.type
- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException
- IOException
-
readValue
public <T> T readValue(@NonNull @io.micronaut.core.annotation.NonNull byte[] byteArray, @NonNull @NonNull Argument<T> type) throws IOException Description copied from interface:JsonMapper
Parse and map json from the given byte array.- Specified by:
readValue
in interfaceJsonMapper
- Type Parameters:
T
- Type variable of the return type.- Parameters:
byteArray
- The input data.type
- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException
- IOException
-
readValue
Description copied from interface:JsonMapper
Parse and map json from the given byte buffer.- Specified by:
readValue
in interfaceJsonMapper
- Type Parameters:
T
- Type variable of the return type.- Parameters:
byteBuffer
- The input data.type
- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException
- IOException
-
writeValue
public void writeValue(@NonNull @NonNull OutputStream outputStream, @Nullable @Nullable Object object) throws IOException Description copied from interface:JsonMapper
Write an object as json.- Specified by:
writeValue
in interfaceJsonMapper
- Parameters:
outputStream
- The stream to write to.object
- The object to serialize.- Throws:
IOException
- IOException
-
writeValue
public <T> void writeValue(@NonNull @NonNull OutputStream outputStream, @NonNull @NonNull Argument<T> type, T object) throws IOException Description copied from interface:JsonMapper
Write an object as json.- Specified by:
writeValue
in interfaceJsonMapper
- Type Parameters:
T
- The generic type- Parameters:
outputStream
- The stream to write to.type
- The object typeobject
- The object to serialize.- Throws:
IOException
- IOException
-
writeValueAsBytes
Description copied from interface:JsonMapper
Write an object as json.- Specified by:
writeValueAsBytes
in interfaceJsonMapper
- Parameters:
object
- The object to serialize.- Returns:
- The serialized encoded json.
- Throws:
IOException
- IOException
-
writeValueAsBytes
public <T> byte[] writeValueAsBytes(@NonNull @NonNull Argument<T> type, T object) throws IOException Description copied from interface:JsonMapper
Write an object as json.- Specified by:
writeValueAsBytes
in interfaceJsonMapper
- Type Parameters:
T
- The generidc type- Parameters:
type
- The object typeobject
- The object to serialize.- Returns:
- The serialized encoded json.
- Throws:
IOException
- IOException
-
updateValueFromTree
Description copied from interface:JsonMapper
Update an object from json data.- Specified by:
updateValueFromTree
in interfaceJsonMapper
- Parameters:
value
- The object to update.tree
- The json data to update from.- Throws:
IOException
- If there are any mapping exceptions (e.g. illegal values).
-
cloneWithFeatures
Description copied from interface:JsonMapper
Create a copy of this mapper with the given json features as returned byJsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata)
.- Specified by:
cloneWithFeatures
in interfaceJsonMapper
- Parameters:
features
- The json features to configure.- Returns:
- A new mapper.
-
cloneWithViewClass
Description copied from interface:JsonMapper
Create a copy of this mapper with the given view class.- Specified by:
cloneWithViewClass
in interfaceJsonMapper
- Parameters:
viewClass
- The view class to use for serialization and deserialization.- Returns:
- A new mapper.
-
getStreamConfig
- Specified by:
getStreamConfig
in interfaceJsonMapper
- Returns:
- The configured stream config.
-
createReactiveParser
@NonNull public @NonNull Processor<byte[],JsonNode> createReactiveParser(@NonNull @NonNull Consumer<Processor<byte[], JsonNode>> onSubscribe, boolean streamArray) Description copied from interface:JsonMapper
- Specified by:
createReactiveParser
in interfaceJsonMapper
- Parameters:
onSubscribe
- An additional function to invoke with this processor when the returned processor is subscribed to.streamArray
- Whether to return a top-level json array as a stream of elements rather than a single array.- Returns:
- The reactive processor.
-
detectFeatures
@NonNull public @NonNull Optional<JsonFeatures> detectFeatures(@NonNull @NonNull AnnotationMetadata annotations) Description copied from interface:JsonMapper
DetectJsonFeatures
from the given annotation data.- Specified by:
detectFeatures
in interfaceJsonMapper
- Parameters:
annotations
- The annotations to scan.- Returns:
- The json features for use in
JsonMapper.cloneWithFeatures(io.micronaut.json.JsonFeatures)
, or an empty optional if there were no feature annotations detected (or feature annotations are not supported).
-