com.hazelcast.util

## Class JsonUtil

- java.lang.Object
- - com.hazelcast.util.JsonUtil

-     public final class JsonUtil
      extends Object

  Utility class to deal with Json.

- - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Map<String,Comparable>` | `fromJsonObject(com.hazelcast.internal.json.JsonObject object)` Transforms the provided `JsonObject` int a map of name/value pairs.
    `static com.hazelcast.internal.json.JsonArray` | `getArray(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as an array.
    `static com.hazelcast.internal.json.JsonArray` | `getArray(com.hazelcast.internal.json.JsonObject object, String field, com.hazelcast.internal.json.JsonArray defaultValue)` Returns a field in a Json object as an array.
    `static boolean` | `getBoolean(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as a boolean.
    `static boolean` | `getBoolean(com.hazelcast.internal.json.JsonObject object, String field, boolean defaultValue)` Returns a field in a Json object as a boolean.
    `static double` | `getDouble(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as a double.
    `static double` | `getDouble(com.hazelcast.internal.json.JsonObject object, String field, double defaultValue)` Returns a field in a Json object as a double.
    `static float` | `getFloat(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as a float.
    `static float` | `getFloat(com.hazelcast.internal.json.JsonObject object, String field, float defaultValue)` Returns a field in a Json object as a float.
    `static int` | `getInt(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as an int.
    `static int` | `getInt(com.hazelcast.internal.json.JsonObject object, String field, int defaultValue)` Returns a field in a Json object as an int.
    `static long` | `getLong(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as a long.
    `static long` | `getLong(com.hazelcast.internal.json.JsonObject object, String field, long defaultValue)` Returns a field in a Json object as a long.
    `static com.hazelcast.internal.json.JsonObject` | `getObject(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as an object.
    `static com.hazelcast.internal.json.JsonObject` | `getObject(com.hazelcast.internal.json.JsonObject object, String field, com.hazelcast.internal.json.JsonObject defaultValue)` Returns a field in a Json object as an object.
    `static String` | `getString(com.hazelcast.internal.json.JsonObject object, String field)` Returns a field in a Json object as a string.
    `static String` | `getString(com.hazelcast.internal.json.JsonObject object, String field, String defaultValue)` Returns a field in a Json object as a string.
    `static String` | `toJson(Object value)` Returns the JSON representation of the provided `value`
    `static com.hazelcast.internal.json.JsonObject` | `toJsonObject(Map<String,?> map)` Transforms the provided map of name/value pairs into a `JsonObject`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getInt

          public static int getInt(com.hazelcast.internal.json.JsonObject object,
                                   String field)

      Returns a field in a Json object as an int. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as an int

    - #### getInt

          public static int getInt(com.hazelcast.internal.json.JsonObject object,
                                   String field,
                                   int defaultValue)

      Returns a field in a Json object as an int.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as an int

    - #### getLong

          public static long getLong(com.hazelcast.internal.json.JsonObject object,
                                     String field)

      Returns a field in a Json object as a long. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a long

    - #### getLong

          public static long getLong(com.hazelcast.internal.json.JsonObject object,
                                     String field,
                                     long defaultValue)

      Returns a field in a Json object as a long.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a long

    - #### getDouble

          public static double getDouble(com.hazelcast.internal.json.JsonObject object,
                                         String field)

      Returns a field in a Json object as a double. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a double

    - #### getDouble

          public static double getDouble(com.hazelcast.internal.json.JsonObject object,
                                         String field,
                                         double defaultValue)

      Returns a field in a Json object as a double.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a double

    - #### getFloat

          public static float getFloat(com.hazelcast.internal.json.JsonObject object,
                                       String field)

      Returns a field in a Json object as a float. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a float

    - #### getFloat

          public static float getFloat(com.hazelcast.internal.json.JsonObject object,
                                       String field,
                                       float defaultValue)

      Returns a field in a Json object as a float.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a float

    - #### getString

          public static String getString(com.hazelcast.internal.json.JsonObject object,
                                         String field)

      Returns a field in a Json object as a string. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a string

    - #### getString

          public static String getString(com.hazelcast.internal.json.JsonObject object,
                                         String field,
                                         String defaultValue)

      Returns a field in a Json object as a string.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a string

    - #### getBoolean

          public static boolean getBoolean(com.hazelcast.internal.json.JsonObject object,
                                           String field)

      Returns a field in a Json object as a boolean. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a boolean

    - #### getBoolean

          public static boolean getBoolean(com.hazelcast.internal.json.JsonObject object,
                                           String field,
                                           boolean defaultValue)

      Returns a field in a Json object as a boolean.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a boolean

    - #### getArray

          public static com.hazelcast.internal.json.JsonArray getArray(com.hazelcast.internal.json.JsonObject object,
                                                                       String field)

      Returns a field in a Json object as an array. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as an array

    - #### getArray

          public static com.hazelcast.internal.json.JsonArray getArray(com.hazelcast.internal.json.JsonObject object,
                                                                       String field,
                                                                       com.hazelcast.internal.json.JsonArray defaultValue)

      Returns a field in a Json object as an array.
      Parameters:
        `object` - the Json Object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a Json array

    - #### getObject

          public static com.hazelcast.internal.json.JsonObject getObject(com.hazelcast.internal.json.JsonObject object,
                                                                         String field)

      Returns a field in a Json object as an object. Throws IllegalArgumentException if the field value is null.
      Parameters:
        `object` - the Json object
        `field` - the field in the Json object to return
      Returns:
        the Json field value as a Json object

    - #### getObject

          public static com.hazelcast.internal.json.JsonObject getObject(com.hazelcast.internal.json.JsonObject object,
                                                                         String field,
                                                                         com.hazelcast.internal.json.JsonObject defaultValue)

      Returns a field in a Json object as an object.
      Parameters:
        `object` - the Json object
        `field` - the field in the Json object to return
        `defaultValue` - a default value for the field if the field value is null
      Returns:
        the Json field value as a Json object

    - #### fromJsonObject

          public static Map<String,Comparable> fromJsonObject(com.hazelcast.internal.json.JsonObject object)

      Transforms the provided `JsonObject` int a map of name/value pairs.
      Parameters:
        `object` - the JSON object
      Returns:
        map from JSON name to value

    - #### toJsonObject

          public static com.hazelcast.internal.json.JsonObject toJsonObject(Map<String,?> map)

      Transforms the provided map of name/value pairs into a `JsonObject`.
      Parameters:
        `map` - map of JSON name-value pairs
      Returns:
        the JSON object

    - #### toJson

          public static String toJson(Object value)

      Returns the JSON representation of the provided `value`
      Parameters:
        `value` - the value to serialize to JSON
      Returns:
        the serialized value

Copyright © 2020. All rights reserved.