- All Superinterfaces:
org.miaixz.bus.core.Provider,Serializable
- All Known Implementing Classes:
AbstractJsonProvider,FastJsonProvider,GsonProvider,JacksonProvider
public interface JsonProvider
extends org.miaixz.bus.core.Provider
Defines the contract for a JSON service provider. This interface specifies a set of common methods for JSON
serialization and deserialization, allowing for different underlying JSON libraries (e.g., Jackson, Gson, Fastjson)
to be used interchangeably.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Method Summary
Modifier and TypeMethodDescription<T> TExtracts the value of a specific field from a JSON string.booleanChecks if a given string is a valid, well-formed JSON string.toJsonString(Object object) Converts an object into its JSON string representation.toJsonString(Object object, String format) Converts an object into its JSON string representation, with a specified date format.<T> List<T> Parses a JSON string into aList.<T> List<T> Parses a JSON string into aListof objects of the specified class.<T> List<T> Parses a JSON string into aListof a specific generic type.<K,V> Map <K, V> Converts an object into aMap.<K,V> Map <K, V> Parses a JSON string into aMap.<T> TParses a JSON string into an object of the specified class.<T> TConverts aMapinto a plain old Java object (POJO) of the specified class.default Objecttype()Returns the type of this JSON provider.
-
Method Details
-
toJsonString
Converts an object into its JSON string representation.- Parameters:
object- The object to be serialized.- 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 serialized.format- The date format string to use for date/time objects, 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 deserialized.clazz- The class of the target object.- Returns:
- The deserialized object.
-
toPojo
Converts aMapinto a plain old Java object (POJO) of the specified class.- Type Parameters:
T- The type of the target POJO.- Parameters:
map- The source map.clazz- The class of the target POJO.- Returns:
- The POJO converted from the map.
-
toList
Parses a JSON string into aList.- Type Parameters:
T- The generic type of the elements in the list.- Parameters:
json- The JSON string to be deserialized.- Returns:
- The resulting
List.
-
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 deserialized.clazz- The class of the elements in the list.- Returns:
- The resulting
List.
-
toList
Parses a JSON string into aListof a specific generic type. -
toMap
Parses a JSON string into aMap.- Type Parameters:
K- The type of the keys in the map.V- The type of the values in the map.- Parameters:
json- The JSON string to be deserialized.- Returns:
- The resulting
Map.
-
toMap
Converts an object into aMap.- Type Parameters:
K- The type of the keys in the map.V- The type of the values in the map.- 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, well-formed JSON string.- Parameters:
json- The string to be checked.- Returns:
trueif the string is a valid JSON,falseotherwise.
-
type
Returns the type of this JSON provider.- Specified by:
typein interfaceorg.miaixz.bus.core.Provider- Returns:
- The provider type, which is
EnumValue.Povider.JSON.
-