Class JsonUtil
- java.lang.Object
-
- org.glassfish.admin.rest.utils.JsonUtil
-
public class JsonUtil extends Object
Various utility methods for processing JSON.- Author:
- jdlee, jcoustick
-
-
Field Summary
Fields Modifier and Type Field Description static String
CONFIDENTIAL_PROPERTY_SET
static String
CONFIDENTIAL_PROPERTY_UNSET
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static jakarta.json.JsonObject
accumalate(jakarta.json.JsonObject jsonObject, String key, jakarta.json.JsonValue value)
Puts a value into aJsonObject
with the specified key.static int
getInt(jakarta.json.JsonObject jsonObject, String key, int dflt)
Gets an integer from aJsonObject
static jakarta.json.JsonObject
getJsonForRestModel(RestModel model, boolean hideConfidentialProperties)
static jakarta.json.JsonValue
getJsonObject(Object object, boolean hideConfidentialProperties)
Deprecated.As of 5.0, replaced bygetJsonValue(Object)
as a more accurately named method with the removal of Jettison the return value is no longer JSONObject but JsonValue.static jakarta.json.JsonValue
getJsonValue(Object object)
Converts an object to a JsonValuestatic jakarta.json.JsonValue
getJsonValue(Object object, boolean hideConfidentialProperties)
Converts an object to a JsonValuestatic String
getString(jakarta.json.JsonObject jsonObject, String key, String dflt)
Gets a String from aJsonObject
static boolean
isConfidentialProperty(Class clazz, String getterMethodName)
static List<Object>
jsonArraytoArray(jakarta.json.JsonArray array)
static Map<String,Object>
jsonObjectToMap(jakarta.json.JsonObject object)
static Object
jsonValueToRaw(jakarta.json.JsonValue value)
Converts a JsonValue to the java standard type it represents.static jakarta.json.JsonArray
processCollection(Collection c)
static jakarta.json.JsonObject
processMap(Map map)
-
-
-
Field Detail
-
CONFIDENTIAL_PROPERTY_SET
public static final String CONFIDENTIAL_PROPERTY_SET
- See Also:
- Constant Field Values
-
CONFIDENTIAL_PROPERTY_UNSET
public static final String CONFIDENTIAL_PROPERTY_UNSET
-
-
Method Detail
-
getJsonValue
public static jakarta.json.JsonValue getJsonValue(Object object) throws jakarta.json.JsonException
Converts an object to a JsonValueThe object must be one of
JsonValue
,Collection
,Map
,ResponseBody
,String
,Integer
,Long
,Double
,Boolean
,BigInteger
,BigDecimal
, a class that has a REST model or an array of one of the above.- Parameters:
object
- The object to convert- Returns:
- The resulting JsonValue
- Throws:
jakarta.json.JsonException
- If the object cannot be converted to a JsonValue
-
getJsonValue
public static jakarta.json.JsonValue getJsonValue(Object object, boolean hideConfidentialProperties) throws jakarta.json.JsonException
Converts an object to a JsonValueThe object must be one of
JsonValue
,Collection
,Map
,ResponseBody
,String
,Integer
,Long
,Double
,Boolean
,BigInteger
,BigDecimal
, a class that has a REST model or an array of one of the above.- Parameters:
object
- The object to converthideConfidentialProperties
-- Returns:
- resulting JsonValue
- Throws:
jakarta.json.JsonException
- If the object cannot be converted to a JsonValue
-
getJsonObject
@Deprecated public static jakarta.json.JsonValue getJsonObject(Object object, boolean hideConfidentialProperties) throws jakarta.json.JsonException
Deprecated.As of 5.0, replaced bygetJsonValue(Object)
as a more accurately named method with the removal of Jettison the return value is no longer JSONObject but JsonValue.Converts an object to a JsonValueThe object must be one of
JsonValue
,Collection
,Map
,ResponseBody
,String
,Integer
,Long
,Double
,Boolean
,BigInteger
,BigDecimal
, a class that has a REST model or an array of one of the above.- Parameters:
object
- The object to converthideConfidentialProperties
-- Returns:
- Throws:
jakarta.json.JsonException
- If the object cannot be converted to a JsonValue
-
getJsonForRestModel
public static jakarta.json.JsonObject getJsonForRestModel(RestModel model, boolean hideConfidentialProperties)
-
isConfidentialProperty
public static boolean isConfidentialProperty(Class clazz, String getterMethodName)
-
processCollection
public static jakarta.json.JsonArray processCollection(Collection c) throws jakarta.json.JsonException
- Parameters:
c
-- Returns:
- Throws:
jakarta.json.JsonException
-
processMap
public static jakarta.json.JsonObject processMap(Map map) throws jakarta.json.JsonException
- Throws:
jakarta.json.JsonException
-
getString
public static String getString(jakarta.json.JsonObject jsonObject, String key, String dflt)
Gets a String from aJsonObject
- Parameters:
jsonObject
-key
-dflt
- returned if there is no mapping for the key- Returns:
-
getInt
public static int getInt(jakarta.json.JsonObject jsonObject, String key, int dflt)
Gets an integer from aJsonObject
- Parameters:
jsonObject
-key
-dflt
- returned if there is no mapping for the key- Returns:
-
accumalate
public static jakarta.json.JsonObject accumalate(jakarta.json.JsonObject jsonObject, String key, jakarta.json.JsonValue value)
Puts a value into aJsonObject
with the specified key.If the key already exists then a
JsonArray
is used to store all the values. This differs toMap.put(Object, Object)
as put replaces the value if the key already exists.- Parameters:
jsonObject
-key
-value
-- Returns:
- Since:
- 5.0
-
jsonObjectToMap
public static Map<String,Object> jsonObjectToMap(jakarta.json.JsonObject object)
Converts aJsonObject
to aMap
<String
,Object
> where the values of all of the basic type (Integer
,String
etc.), and notJsonValue
.- Parameters:
object
- The JsonObject to convert to a Map- Returns:
- Since:
- 5.0
- See Also:
jsonValueToRaw(jakarta.json.JsonValue)
-
jsonArraytoArray
public static List<Object> jsonArraytoArray(jakarta.json.JsonArray array)
Converts aJsonArray
to aList
<Object
> where the objects are all the standard java types represented by the values in the array- Parameters:
array
- The JsonArray to convert toList
- Returns:
- Since:
- 5.0
- See Also:
jsonValueToRaw(jakarta.json.JsonValue)
-
jsonValueToRaw
public static Object jsonValueToRaw(jakarta.json.JsonValue value)
Converts a JsonValue to the java standard type it represents.JsonArray
->List
<Object
>
JsonObject
->Map
<String
,Object
>
JsonString
->String
JsonNumber
->BigDecimal
JsonValue.TRUE
->Boolean.TRUE
JsonValue.FALSE
->Boolean.FALSE
JsonValue.NULL
->null
- Parameters:
value
-- Returns:
- The java standard type represented by the
JsonValue
- Since:
- 5.0
-
-