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(tools.jackson.databind.ObjectMapper objectMapper) JacksonDatabindMapper(tools.jackson.databind.ObjectMapper objectMapper, boolean allowViews) -
Method Summary
Modifier and TypeMethodDescriptioncloneWithFeatures(JsonFeatures features) Create a copy of this mapper with the given json features as returned byJsonMapper.detectFeatures(io.micronaut.core.annotation.AnnotationMetadata).cloneWithViewClass(Class<?> viewClass) Create a copy of this mapper with the given view class.createReactiveParser(Consumer<Processor<byte[], JsonNode>> onSubscribe, boolean streamArray) createSpecific(Argument<?> type) Specialize this mapper for the given type.detectFeatures(AnnotationMetadata annotations) DetectJsonFeaturesfrom the given annotation data.tools.jackson.databind.ObjectMapper<T> TParse and map json from the given byte array.<T> TreadValue(ByteBuffer<?> byteBuffer, Argument<T> type) Parse and map json from the given byte buffer.<T> TreadValue(ReadBuffer readBuffer, Argument<T> type) Parse and map json from the given read buffer.<T> TreadValue(InputStream inputStream, Argument<T> type) Parse and map json from the given stream.<T> TreadValueFromTree(JsonNode tree, Argument<T> type) Transform aJsonNodeto a value of the given type.voidupdateValueFromTree(Object value, JsonNode tree) Update an object from json data.<T> voidwriteValue(OutputStream outputStream, Argument<T> type, T object) Write an object as json.voidwriteValue(OutputStream outputStream, @Nullable Object object) Write an object as json.<T> byte[]writeValueAsBytes(Argument<T> type, T object) Write an object as json.byte[]writeValueAsBytes(@Nullable Object object) Write an object as json.<T> JsonNodewriteValueToTree(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
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
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
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
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
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
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
-
readValue
Description copied from interface:JsonMapperParse and map json from the given read buffer.- Specified by:
readValuein interfaceJsonMapper- Type Parameters:
T- Type variable of the return type.- Parameters:
readBuffer- The input data.type- The type to deserialize to.- Returns:
- The deserialized object.
- Throws:
IOException- IOException
-
writeValue
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(OutputStream outputStream, 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
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
public Processor<byte[],JsonNode> createReactiveParser(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
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).
-