public interface JsonMapper
Modifier and Type | Method and Description |
---|---|
default JsonMapper |
cloneWithFeatures(JsonFeatures features)
Create a copy of this mapper with the given json features as returned by
detectFeatures(io.micronaut.core.annotation.AnnotationMetadata) . |
default JsonMapper |
cloneWithViewClass(java.lang.Class<?> viewClass)
Create a copy of this mapper with the given view class.
|
org.reactivestreams.Processor<byte[],JsonNode> |
createReactiveParser(java.util.function.Consumer<org.reactivestreams.Processor<byte[],JsonNode>> onSubscribe,
boolean streamArray)
Create a reactive
Processor that accepts json bytes and parses them as JsonNode s. |
default java.util.Optional<JsonFeatures> |
detectFeatures(AnnotationMetadata annotations)
Detect
JsonFeatures from the given annotation data. |
JsonStreamConfig |
getStreamConfig() |
<T> T |
readValue(byte[] byteArray,
Argument<T> type)
Parse and map json from the given byte array.
|
<T> T |
readValue(java.io.InputStream inputStream,
Argument<T> type)
Parse and map json from the given stream.
|
default <T> T |
readValue(java.lang.String string,
Argument<T> type)
Parse and map json from the given string.
|
<T> T |
readValueFromTree(JsonNode tree,
Argument<T> type)
Transform a
JsonNode to a value of the given type. |
default <T> T |
readValueFromTree(JsonNode tree,
java.lang.Class<T> type)
Transform a
JsonNode to a value of the given type. |
default void |
updateValueFromTree(java.lang.Object value,
JsonNode tree)
Update an object from json data.
|
void |
writeValue(java.io.OutputStream outputStream,
java.lang.Object object)
Write an object as json.
|
byte[] |
writeValueAsBytes(java.lang.Object object)
Write an object as json.
|
JsonNode |
writeValueToTree(java.lang.Object value)
Transform an object value to a json tree.
|
<T> T readValueFromTree(@NonNull JsonNode tree, @NonNull Argument<T> type) throws java.io.IOException
JsonNode
to a value of the given type.T
- Type variable of the return type.tree
- The input json data.type
- The type to deserialize.java.io.IOException
default <T> T readValueFromTree(@NonNull JsonNode tree, @NonNull java.lang.Class<T> type) throws java.io.IOException
JsonNode
to a value of the given type.T
- Type variable of the return type.tree
- The input json data.type
- The type to deserialize.java.io.IOException
<T> T readValue(@NonNull java.io.InputStream inputStream, @NonNull Argument<T> type) throws java.io.IOException
T
- Type variable of the return type.inputStream
- The input data.type
- The type to deserialize to.java.io.IOException
<T> T readValue(@NonNull byte[] byteArray, @NonNull Argument<T> type) throws java.io.IOException
T
- Type variable of the return type.byteArray
- The input data.type
- The type to deserialize to.java.io.IOException
default <T> T readValue(@NonNull java.lang.String string, @NonNull Argument<T> type) throws java.io.IOException
T
- Type variable of the return type.string
- The input data.type
- The type to deserialize to.java.io.IOException
@NonNull org.reactivestreams.Processor<byte[],JsonNode> createReactiveParser(@NonNull java.util.function.Consumer<org.reactivestreams.Processor<byte[],JsonNode>> onSubscribe, boolean streamArray)
Processor
that accepts json bytes and parses them as JsonNode
s.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 JsonNode writeValueToTree(@Nullable java.lang.Object value) throws java.io.IOException
value
- The object value to transform.java.io.IOException
- If there are any mapping exceptions (e.g. illegal values).void writeValue(@NonNull java.io.OutputStream outputStream, @Nullable java.lang.Object object) throws java.io.IOException
outputStream
- The stream to write to.object
- The object to serialize.java.io.IOException
byte[] writeValueAsBytes(@Nullable java.lang.Object object) throws java.io.IOException
object
- The object to serialize.java.io.IOException
default void updateValueFromTree(java.lang.Object value, @NonNull JsonNode tree) throws java.io.IOException
value
- The object to update.tree
- The json data to update from.java.io.IOException
- If there are any mapping exceptions (e.g. illegal values).java.lang.UnsupportedOperationException
- If this operation is not supported.@NonNull default JsonMapper cloneWithFeatures(@NonNull JsonFeatures features)
detectFeatures(io.micronaut.core.annotation.AnnotationMetadata)
.features
- The json features to configure.@NonNull default java.util.Optional<JsonFeatures> detectFeatures(@NonNull AnnotationMetadata annotations)
JsonFeatures
from the given annotation data.annotations
- The annotations to scan.cloneWithFeatures(io.micronaut.json.JsonFeatures)
, or an empty optional if there were no feature
annotations detected (or feature annotations are not supported).@NonNull default JsonMapper cloneWithViewClass(@NonNull java.lang.Class<?> viewClass)
viewClass
- The view class to use for serialization and deserialization.java.lang.UnsupportedOperationException
- If views are not supported by this mapper.@NonNull JsonStreamConfig getStreamConfig()