Class JsonUtil
java.lang.Object
org.eclipse.keyple.core.util.json.JsonUtil
Json utilities based on Gson (com.google.gson).
- Since:
- 2.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic com.google.gson.Gson
Gets the singleton instance of the parser.static void
registerTypeAdapter
(Class<?> matchingClass, Object adapter, boolean withSubclasses) Registers a new type adapter.static String
Formats the provided object as a json string.
-
Method Details
-
getParser
public static com.google.gson.Gson getParser()Gets the singleton instance of the parser.If not created yet, a default instance is created.
Caution: to use the
Gson
object in return, the invoker must also import the Gson library from Google (see the manifest of the NOTICE document for the version to be used).- Returns:
- a not null instance.
- Since:
- 2.0.0
-
registerTypeAdapter
public static void registerTypeAdapter(Class<?> matchingClass, Object adapter, boolean withSubclasses) Registers a new type adapter.- Parameters:
matchingClass
- The type to be registered.adapter
- The type adapter to be registered (should implementJsonSerializer
and/orJsonDeserializer
).withSubclasses
- Apply this adapter to subclasses of matchingClass also.- Since:
- 2.0.0
-
toJson
Formats the provided object as a json string.- Parameters:
obj
- The object to format.- Returns:
- A not empty String.
- Since:
- 2.0.0
-