Class JsonUtil
- java.lang.Object
-
- org.eclipse.keyple.core.util.json.JsonUtil
-
public final class JsonUtil extends java.lang.ObjectJson utilities based on Gson (com.google.gson).- Since:
- 2.0.0
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static com.google.gson.GsongetParser()Gets the singleton instance of the parser.static voidregisterTypeAdapter(java.lang.Class<?> matchingClass, java.lang.Object adapter, boolean withSubclasses)Registers a new type adapter.static java.lang.StringtoJson(java.lang.Object obj)Formats the provided object as a json string.
-
-
-
Method Detail
-
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
Gsonobject 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(java.lang.Class<?> matchingClass, java.lang.Object adapter, boolean withSubclasses)Registers a new type adapter.- Parameters:
matchingClass- The type to be registered.adapter- The type adapter to be registered (should implementJsonSerializerand/orJsonDeserializer).withSubclasses- Apply this adapter to subclasses of matchingClass also.- Since:
- 2.0.0
-
toJson
public static java.lang.String toJson(java.lang.Object obj)
Formats the provided object as a json string.- Parameters:
obj- The object to format.- Returns:
- A not empty String.
- Since:
- 2.0.0
-
-