Class JsonUtil

java.lang.Object
org.eclipse.keyple.core.util.json.JsonUtil

public final class JsonUtil extends Object
Json utilities based on Gson (com.google.gson).
Since:
2.0.0
  • 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 implement JsonSerializer and/or JsonDeserializer).
      withSubclasses - Apply this adapter to subclasses of matchingClass also.
      Since:
      2.0.0
    • toJson

      public static String toJson(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