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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty used to specify whether JSON view is enabled. -
Constructor Summary
ConstructorsConstructorDescriptionJacksonDatabindMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper) JacksonDatabindMapper(com.fasterxml.jackson.databind.ObjectMapper objectMapper, boolean allowViews) -
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(@NonNull Argument<?> type) Specialize this mapper for the given type.detectFeatures(@NonNull AnnotationMetadata annotations) DetectJsonFeaturesfrom the given annotation data.com.fasterxml.jackson.databind.ObjectMapper<T> TParse and map json from the given byte array.<T> TreadValue(@NonNull ByteBuffer<?> byteBuffer, @NonNull Argument<T> type) Parse and map json from the given byte buffer.<T> TreadValue(@NonNull InputStream inputStream, @NonNull Argument<T> type) Parse and map json from the given stream.<T> TreadValueFromTree(@NonNull JsonNode tree, @NonNull Argument<T> type) Transform aJsonNodeto a value of the given type.voidupdateValueFromTree(Object value, @NonNull JsonNode tree) Update an object from json data.<T> voidwriteValue(@NonNull OutputStream outputStream, @NonNull Argument<T> type, T object) Write an object as json.voidwriteValue(@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, waitMethods inherited from interface io.micronaut.json.JsonMapper
readValue, readValue, readValue, readValue, readValueFromTree, writeValueAsString, writeValueAsString, writeValueAsString
-
Field Details
-
PROPERTY_JSON_VIEW_ENABLED
Property used to specify whether JSON view is enabled.- See Also:
-
-
Constructor Details
-
JacksonDatabindMapper
-
JacksonDatabindMapper
-
JacksonDatabindMapper
-
-
Method Details
-
getObjectMapper
-
createSpecific
Description copied from interface:JsonMapperSpecialize this mapper for the given type. Read and write operations on the returned mapper may only be called with that type.- Specified by:
createSpecificin 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:JsonMapperTransform aJsonNodeto a value of the given type.- Specified by:
readValueFromTreein 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:JsonMapperTransform an object value to a json tree.- Specified by:
writeValueToTreein 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:JsonMapperTransform an object value to a json tree.- Specified by:
writeValueToTreein 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:JsonMapperParse and map json from the given stream.- Specified by:
readValuein 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(byte @NonNull [] byteArray, @NonNull @NonNull Argument<T> type) throws IOException Description copied from interface:JsonMapperParse and map json from the given byte array.- Specified by:
readValuein 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
public <T> T readValue(@NonNull @NonNull ByteBuffer<?> byteBuffer, @NonNull @NonNull Argument<T> type) throws IOException Description copied from interface:JsonMapperParse and map json from the given byte buffer.- Specified by:
readValuein 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:JsonMapperWrite an object as json.- Specified by:
writeValuein 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:JsonMapperWrite an object as json.- Specified by:
writeValuein 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:JsonMapperWrite an object as json.- Specified by:
writeValueAsBytesin 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:JsonMapperWrite an object as json.- Specified by:
writeValueAsBytesin interfaceJsonMapper- Type Parameters:
T- The generic type- Parameters:
type- The object typeobject- The object to serialize.- Returns:
- The serialized encoded json.
- Throws:
IOException- IOException
-
updateValueFromTree
Description copied from interface:JsonMapperUpdate an object from json data.- Specified by:
updateValueFromTreein 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:JsonMapperCreate a copy of this mapper with the given json features as returned byJsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata).- Specified by:
cloneWithFeaturesin interfaceJsonMapper- Parameters:
features- The json features to configure.- Returns:
- A new mapper.
-
cloneWithViewClass
Description copied from interface:JsonMapperCreate a copy of this mapper with the given view class.- Specified by:
cloneWithViewClassin interfaceJsonMapper- Parameters:
viewClass- The view class to use for serialization and deserialization.- Returns:
- A new mapper.
-
getStreamConfig
- Specified by:
getStreamConfigin 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:
createReactiveParserin 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:JsonMapperDetectJsonFeaturesfrom the given annotation data.- Specified by:
detectFeaturesin 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).
-