public class JsonSerdeUtil extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode> |
asSpecificNodeType(String json,
Class<T> clazz)
Parses the provided JSON string and casts it to the specified type of
JsonNode . |
static <T> T |
convertValue(Object fromValue,
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef) |
static <T> T |
extractValue(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<T> valueType,
String... path)
Parses a JSON string and extracts a value of the specified type from the given path keys.
|
static <T> T |
extractValueOrDefault(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode,
Class<T> valueType,
T defaultValue,
String... path)
Parses a JSON string and extracts a value of the specified type from the given path keys.
|
static <T> T |
fromJson(String json,
Class<T> clazz) |
static <T> T |
fromJson(String json,
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference<T> typeReference) |
static <T extends org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode> |
getNodeAs(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode root,
String fieldName,
Class<T> clazz)
Retrieves a specific node from the given root node and casts it to the specified type.
|
static boolean |
isNodeExists(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode,
String... path)
Checks if a specified node exists in a JSON string.
|
static boolean |
isNull(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode) |
static <V> LinkedHashMap<String,V> |
parseJsonMap(String jsonString,
Class<V> valueType) |
static <T> String |
toFlatJson(T t) |
static <T> String |
toJson(T t) |
static String |
writeValueAsString(Object value) |
public static <V> LinkedHashMap<String,V> parseJsonMap(String jsonString, Class<V> valueType)
@Nullable public static <T extends org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode> T getNodeAs(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode root, String fieldName, Class<T> clazz)
T
- The type of the node to be returned.root
- The root node from which the specific node is to be retrieved.fieldName
- The name of the field to retrieve.clazz
- The class of the node to be returned.IllegalArgumentException
- if the node is not of the expected type.public static <T> T fromJson(String json, org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
public static <T> String toJson(T t)
public static <T> String toFlatJson(T t)
public static <T extends org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode> T asSpecificNodeType(String json, Class<T> clazz) throws org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
JsonNode
.
This method is useful when the exact subtype of JsonNode
is known beforehand and
needs to be enforced.
T
- The type of the JsonNode to return. Must be a subtype of JsonNode
.json
- The JSON string to parse.clazz
- The expected class type of the parsed JSON.org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
- If there's an error during JSON parsing.IllegalArgumentException
- If the parsed JSON is not of the expected type.public static <T> T extractValueOrDefault(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> valueType, T defaultValue, String... path) throws org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
public static <T> T extractValue(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode, Class<T> valueType, String... path) throws org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
public static boolean isNodeExists(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode, String... path)
public static <T> T convertValue(Object fromValue, org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference<T> toValueTypeRef)
public static String writeValueAsString(Object value) throws org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException
public static boolean isNull(org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode jsonNode)
Copyright © 2023–2024 The Apache Software Foundation. All rights reserved.