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(Class<?> viewClass)
Create a copy of this mapper with the given view class.
|
Processor<byte[],JsonNode> |
createReactiveParser(Consumer<Processor<byte[],JsonNode>> onSubscribe,
boolean streamArray)
|
default 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(InputStream inputStream,
Argument<T> type)
Parse and map json from the given stream.
|
default <T> T |
readValue(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,
Class<T> type)
Transform a
JsonNode to a value of the given type. |
default 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.
|
<T> T readValueFromTree(@NonNull JsonNode tree, @NonNull Argument<T> type) throws 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.IOException
- IOExceptiondefault <T> T readValueFromTree(@NonNull JsonNode tree, @NonNull Class<T> type) throws 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.IOException
- IOException<T> T readValue(@NonNull InputStream inputStream, @NonNull Argument<T> type) throws IOException
T
- Type variable of the return type.inputStream
- The input data.type
- The type to deserialize to.IOException
- IOException<T> T readValue(@NonNull byte[] byteArray, @NonNull Argument<T> type) throws IOException
T
- Type variable of the return type.byteArray
- The input data.type
- The type to deserialize to.IOException
- IOExceptiondefault <T> T readValue(@NonNull String string, @NonNull Argument<T> type) throws IOException
T
- Type variable of the return type.string
- The input data.type
- The type to deserialize to.IOException
- IOException@NonNull Processor<byte[],JsonNode> createReactiveParser(@NonNull Consumer<Processor<byte[],JsonNode>> onSubscribe, boolean streamArray)
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 Object value) throws IOException
value
- The object value to transform.IOException
- If there are any mapping exceptions (e.g. illegal values).@NonNull <T> JsonNode writeValueToTree(@NonNull Argument<T> type, @Nullable T value) throws IOException
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).void writeValue(@NonNull OutputStream outputStream, @Nullable Object object) throws IOException
outputStream
- The stream to write to.object
- The object to serialize.IOException
- IOException<T> void writeValue(@NonNull OutputStream outputStream, @NonNull Argument<T> type, @Nullable T object) throws IOException
T
- The generic typeoutputStream
- The stream to write to.type
- The object typeobject
- The object to serialize.IOException
- IOExceptionbyte[] writeValueAsBytes(@Nullable Object object) throws IOException
object
- The object to serialize.IOException
- IOException<T> byte[] writeValueAsBytes(@NonNull Argument<T> type, @Nullable T object) throws IOException
T
- The generidc typetype
- The object typeobject
- The object to serialize.IOException
- IOExceptiondefault void updateValueFromTree(Object value, @NonNull JsonNode tree) throws IOException
value
- The object to update.tree
- The json data to update from.IOException
- If there are any mapping exceptions (e.g. illegal values).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 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 Class<?> viewClass)
viewClass
- The view class to use for serialization and deserialization.UnsupportedOperationException
- If views are not supported by this mapper.@NonNull JsonStreamConfig getStreamConfig()