Package io.sockit.gameclient
Class JsonUtil
java.lang.Object
io.sockit.gameclient.JsonUtil
public class JsonUtil extends Object
This class contains convenience/utility methods for the java Json processing api.
-
Constructor Summary
Constructors Constructor Description JsonUtil() -
Method Summary
Modifier and Type Method Description static JsonArrayBuildercreateArrayBuilder()Creates a JsonArrayBuilder that handles nulls gracefullystatic JsonArrayBuildercreateArrayBuilder(Collection<?> collection)Creates a JsonArrayBuilder that handles nulls gracefullystatic JsonArrayBuildercreateArrayBuilder(JsonArray array)Creates a JsonArrayBuilder that handles nulls gracefullystatic JsonObjectBuildercreateObjectBuilder()Creates a JsonObjectBuilder that handles nulls gracefullystatic JsonObjectBuildercreateObjectBuilder(JsonObject jsonObject)Creates a JsonObjectBuilder that handles nulls gracefullystatic booleangetAsBoolean(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a boolean or false if the property does not exist.static booleangetAsBoolean(JsonObject jsonObject, String property, boolean defaultValue)Returns the value of the specified property in the jsonObject as a boolean or defaultValue if the property does not exist.static doublegetAsDouble(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a double or 0 if the property does not exist.static doublegetAsDouble(JsonObject jsonObject, String property, double defaultValue)Returns the value of the specified property in the jsonObject as a double or defaultValue if the property does not exist.static floatgetAsFloat(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a float or 0 if the property does not exist.static floatgetAsFloat(JsonObject jsonObject, String property, float defaultValue)Returns the value of the specified property in the jsonObject as a float or defaultValue if the property does not exist.static intgetAsInt(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as an int or 0 if the property does not exist.static intgetAsInt(JsonObject jsonObject, String property, int defaultValue)Returns the value of the specified property in the jsonObject as an int or defaultValue if the property does not exist.static JsonArraygetAsJsonArray(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a jsonArray or null if the property does not exist.static JsonObjectgetAsJsonObject(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a jsonObject or null if the property does not exist.static longgetAsLong(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a long or 0 if the property does not exist.static longgetAsLong(JsonObject jsonObject, String property, long defaultValue)Returns the value of the specified property in the jsonObject as a long or defaultValue if the property does not exist.static shortgetAsShort(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a short or 0 if the property does not exist.static shortgetAsShort(JsonObject jsonObject, String property, short defaultValue)Returns the value of the specified property in the jsonObject as a short or defaultValue if the property does not exist.static StringgetAsString(JsonObject jsonObject, String property)Returns the value of the specified property in the jsonObject as a String or null if the property does not exist.static StringgetAsString(JsonObject jsonObject, String property, String defaultValue)Returns the value of the specified property in the jsonObject as a String or defaultValue if the property does not exist.static StringgetValueAsString(JsonValue jsonValue)Returns the json value as a Stringstatic JsonArrayreadArray(String jsonString)Parses the specified json String and creates a JsonArraystatic JsonObjectreadObject(String jsonString)Parses the specified json String and creates a JsonObjectstatic JsonArraytoJsonArray(Collection collection)Creates a JsonArray from the specified Collection
-
Constructor Details
-
JsonUtil
public JsonUtil()
-
-
Method Details
-
getValueAsString
Returns the json value as a String- Parameters:
jsonValue- - the json value- Returns:
- String - the json value as a String
-
getAsString
Returns the value of the specified property in the jsonObject as a String or null if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- String - the value of the specified property in the jsonObject
-
getAsString
Returns the value of the specified property in the jsonObject as a String or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- String - the value of the specified property in the jsonObject
-
getAsInt
Returns the value of the specified property in the jsonObject as an int or 0 if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- int - the value of the specified property in the jsonObject as an int
-
getAsInt
Returns the value of the specified property in the jsonObject as an int or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- int - the value of the specified property in the jsonObject as an int
-
getAsLong
Returns the value of the specified property in the jsonObject as a long or 0 if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- long - the value of the specified property in the jsonObject as a long
-
getAsLong
Returns the value of the specified property in the jsonObject as a long or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- long - the value of the specified property in the jsonObject as a long
-
getAsFloat
Returns the value of the specified property in the jsonObject as a float or 0 if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- float - the value of the specified property in the jsonObject as a float
-
getAsFloat
Returns the value of the specified property in the jsonObject as a float or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- float - the value of the specified property in the jsonObject as a float
-
getAsDouble
Returns the value of the specified property in the jsonObject as a double or 0 if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- double - the value of the specified property in the jsonObject as a double
-
getAsDouble
Returns the value of the specified property in the jsonObject as a double or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- double - the value of the specified property in the jsonObject as a double
-
getAsBoolean
Returns the value of the specified property in the jsonObject as a boolean or false if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- boolean - the value of the specified property in the jsonObject as a boolean
-
getAsBoolean
Returns the value of the specified property in the jsonObject as a boolean or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- boolean - the value of the specified property in the jsonObject as a boolean
-
getAsShort
Returns the value of the specified property in the jsonObject as a short or 0 if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- short - the value of the specified property in the jsonObject as a short
-
getAsShort
Returns the value of the specified property in the jsonObject as a short or defaultValue if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returneddefaultValue- - the value to be returned if the property does not exist- Returns:
- short - the value of the specified property in the jsonObject as a short
-
getAsJsonObject
Returns the value of the specified property in the jsonObject as a jsonObject or null if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- JsonObject - the value of the specified property in the jsonObject as a JsonObject
-
getAsJsonArray
Returns the value of the specified property in the jsonObject as a jsonArray or null if the property does not exist.- Parameters:
jsonObject- - the jsonObject whose property value is to be returnedproperty- - the property whose value is to be returned- Returns:
- JsonArray - the value of the specified property in the jsonObject as a JsonArray
-
toJsonArray
Creates a JsonArray from the specified Collection- Parameters:
collection- - the collection from which the JsonArray will be created- Returns:
- JsonArray - a JsonArray based on the specified Collection
-
readObject
Parses the specified json String and creates a JsonObject- Parameters:
jsonString- - the json string to be parsed- Returns:
- JsonObject - the parsed json String as a JsonObject
-
readArray
Parses the specified json String and creates a JsonArray- Parameters:
jsonString- - the json string to be parsed- Returns:
- JsonArray - the parsed json String as a JsonArray
-
createObjectBuilder
Creates a JsonObjectBuilder that handles nulls gracefully- Returns:
- JsonObjectBuilder - a JsonObjectBuilder that handles nulls gracefully
-
createObjectBuilder
Creates a JsonObjectBuilder that handles nulls gracefully- Parameters:
jsonObject- - the initial object in the builder- Returns:
- JsonObjectBuilder - a JsonObjectBuilder that handles nulls gracefully
-
createArrayBuilder
Creates a JsonArrayBuilder that handles nulls gracefully- Returns:
- JsonArrayBuilder - a JsonArrayBuilder that handles nulls gracefully
-
createArrayBuilder
Creates a JsonArrayBuilder that handles nulls gracefully- Parameters:
array- - the initial array in the builder- Returns:
- JsonArrayBuilder - a JsonArrayBuilder that handles nulls gracefully
-
createArrayBuilder
Creates a JsonArrayBuilder that handles nulls gracefully- Parameters:
collection- - the initial data for the builder- Returns:
- JsonArrayBuilder - a JsonArrayBuilder that handles nulls gracefully
-