@Internal @Singleton public final class JacksonDatabindMapper extends Object implements JsonMapper
JsonMapper
.Constructor and Description |
---|
JacksonDatabindMapper() |
JacksonDatabindMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) |
Modifier and Type | Method and Description |
---|---|
JsonMapper |
cloneWithFeatures(JsonFeatures features)
Create a copy of this mapper with the given json features as returned by
JsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata) . |
JsonMapper |
cloneWithViewClass(Class<?> viewClass)
Create a copy of this mapper with the given view class.
|
Processor<byte[],JsonNode> |
createReactiveParser(Consumer<Processor<byte[],JsonNode>> onSubscribe,
boolean streamArray)
|
Optional<JsonFeatures> |
detectFeatures(AnnotationMetadata annotations)
Detect
JsonFeatures from the given annotation data. |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
JsonStreamConfig |
getStreamConfig() |
<T> T |
readValue(byte[] byteArray,
Argument<T> type)
Parse and map json from the given byte array.
|
<T> T |
readValue(InputStream inputStream,
Argument<T> type)
Parse and map json from the given stream.
|
<T> T |
readValueFromTree(JsonNode tree,
Argument<T> type)
Transform a
JsonNode to a value of the given type. |
void |
updateValueFromTree(Object value,
JsonNode tree)
Update an object from json data.
|
<T> void |
writeValue(OutputStream outputStream,
Argument<T> type,
T object)
Write an object as json.
|
void |
writeValue(OutputStream outputStream,
Object object)
Write an object as json.
|
<T> byte[] |
writeValueAsBytes(Argument<T> type,
T object)
Write an object as json.
|
byte[] |
writeValueAsBytes(Object object)
Write an object as json.
|
<T> JsonNode |
writeValueToTree(Argument<T> type,
T value)
Transform an object value to a json tree.
|
JsonNode |
writeValueToTree(Object value)
Transform an object value to a json tree.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
readValue, readValueFromTree
@Inject @Internal public JacksonDatabindMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper)
@Internal public JacksonDatabindMapper()
@Internal public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public <T> T readValueFromTree(@NonNull JsonNode tree, @NonNull Argument<T> type) throws IOException
JsonMapper
JsonNode
to a value of the given type.readValueFromTree
in interface JsonMapper
T
- Type variable of the return type.tree
- The input json data.type
- The type to deserialize.IOException
- IOException@NonNull public JsonNode writeValueToTree(@Nullable Object value) throws IOException
JsonMapper
writeValueToTree
in interface JsonMapper
value
- The object value to transform.IOException
- If there are any mapping exceptions (e.g. illegal values).@NonNull public <T> JsonNode writeValueToTree(@NonNull Argument<T> type, T value) throws IOException
JsonMapper
writeValueToTree
in interface JsonMapper
T
- The type variable of the type.type
- The object typevalue
- The object value to transform.IOException
- If there are any mapping exceptions (e.g. illegal values).public <T> T readValue(@NonNull InputStream inputStream, @NonNull Argument<T> type) throws IOException
JsonMapper
readValue
in interface JsonMapper
T
- Type variable of the return type.inputStream
- The input data.type
- The type to deserialize to.IOException
- IOExceptionpublic <T> T readValue(@NonNull byte[] byteArray, @NonNull Argument<T> type) throws IOException
JsonMapper
readValue
in interface JsonMapper
T
- Type variable of the return type.byteArray
- The input data.type
- The type to deserialize to.IOException
- IOExceptionpublic void writeValue(@NonNull OutputStream outputStream, @Nullable Object object) throws IOException
JsonMapper
writeValue
in interface JsonMapper
outputStream
- The stream to write to.object
- The object to serialize.IOException
- IOExceptionpublic <T> void writeValue(@NonNull OutputStream outputStream, @NonNull Argument<T> type, T object) throws IOException
JsonMapper
writeValue
in interface JsonMapper
T
- The generic typeoutputStream
- The stream to write to.type
- The object typeobject
- The object to serialize.IOException
- IOExceptionpublic byte[] writeValueAsBytes(@Nullable Object object) throws IOException
JsonMapper
writeValueAsBytes
in interface JsonMapper
object
- The object to serialize.IOException
- IOExceptionpublic <T> byte[] writeValueAsBytes(@NonNull Argument<T> type, T object) throws IOException
JsonMapper
writeValueAsBytes
in interface JsonMapper
T
- The generidc typetype
- The object typeobject
- The object to serialize.IOException
- IOExceptionpublic void updateValueFromTree(Object value, @NonNull JsonNode tree) throws IOException
JsonMapper
updateValueFromTree
in interface JsonMapper
value
- The object to update.tree
- The json data to update from.IOException
- If there are any mapping exceptions (e.g. illegal values).@NonNull public JsonMapper cloneWithFeatures(@NonNull JsonFeatures features)
JsonMapper
JsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata)
.cloneWithFeatures
in interface JsonMapper
features
- The json features to configure.@NonNull public JsonMapper cloneWithViewClass(@NonNull Class<?> viewClass)
JsonMapper
cloneWithViewClass
in interface JsonMapper
viewClass
- The view class to use for serialization and deserialization.@NonNull public JsonStreamConfig getStreamConfig()
getStreamConfig
in interface JsonMapper
@NonNull public Processor<byte[],JsonNode> createReactiveParser(@NonNull Consumer<Processor<byte[],JsonNode>> onSubscribe, boolean streamArray)
JsonMapper
createReactiveParser
in interface JsonMapper
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.@NonNull public Optional<JsonFeatures> detectFeatures(@NonNull AnnotationMetadata annotations)
JsonMapper
JsonFeatures
from the given annotation data.detectFeatures
in interface JsonMapper
annotations
- The annotations to scan.JsonMapper.cloneWithFeatures(io.micronaut.json.JsonFeatures)
, or an empty optional if there were no feature
annotations detected (or feature annotations are not supported).