java.lang.Object
org.miaixz.bus.extra.json.JsonKit
A utility class for JSON operations, which automatically identifies the underlying JSON provider via SPI. This class
acts as a facade, providing static methods for common JSON serialization and deserialization tasks.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic JsonProviderRetrieves the globally available singleton JSON provider instance.static <T> TExtracts the value of a specific field from a JSON string.static booleanChecks if a given string is a valid JSON string.static StringtoJsonString(Object object) Converts an object into its JSON string representation.static StringtoJsonString(Object object, String format) Converts an object into its JSON string representation, with a specified date format.static ListParses a JSON string into aList.static <T> List<T> Parses a JSON string into aListof objects of the specified class.static <T> List<T> Parses a JSON string into aListof a specific generic type.static MapConverts an object into aMap.static MapParses a JSON string into aMap.static <T> TParses a JSON string into an object of the specified class.static <T> TConverts aMapinto an object of the specified class.
-
Constructor Details
-
JsonKit
public JsonKit()
-
-
Method Details
-
getProvider
Retrieves the globally available singleton JSON provider instance.- Returns:
- The singleton
JsonProviderinstance.
-
toJsonString
Converts an object into its JSON string representation.- Parameters:
object- The object to be converted.- Returns:
- The JSON string representation of the object.
-
toJsonString
Converts an object into its JSON string representation, with a specified date format.- Parameters:
object- The object to be converted.format- The date format string, e.g., "yyyy-MM-dd HH:mm:ss".- Returns:
- The JSON string representation of the object.
-
toPojo
Parses a JSON string into an object of the specified class.- Type Parameters:
T- The type of the target object.- Parameters:
json- The JSON string to be parsed.clazz- The class of the target object.- Returns:
- The parsed object.
-
toPojo
Converts aMapinto an object of the specified class.- Type Parameters:
T- The type of the target object.- Parameters:
map- The source map.clazz- The class of the target object.- Returns:
- The object converted from the map.
-
toList
Parses a JSON string into aList.- Parameters:
json- The JSON string to be parsed.- Returns:
- The resulting
List.
-
toList
Parses a JSON string into aListof a specific generic type. -
toList
Parses a JSON string into aListof objects of the specified class.- Type Parameters:
T- The type of the elements in the list.- Parameters:
json- The JSON string to be parsed.clazz- The class of the elements in the list.- Returns:
- The resulting
List.
-
toMap
Parses a JSON string into aMap.- Parameters:
json- The JSON string to be parsed.- Returns:
- The resulting
Map.
-
toMap
Converts an object into aMap.- Parameters:
object- The object to be converted.- Returns:
- The resulting
Map.
-
getValue
Extracts the value of a specific field from a JSON string.- Type Parameters:
T- The type of the value to be returned.- Parameters:
json- The JSON string to be parsed.field- The name of the field whose value is to be extracted.- Returns:
- The value of the specified field.
-
isJson
Checks if a given string is a valid JSON string.- Parameters:
json- The string to be checked.- Returns:
trueif the string is a valid JSON,falseotherwise.
-