public class ApiHelper extends Object
| Modifier and Type | Field and Description |
|---|---|
static com.fasterxml.jackson.databind.ObjectMapper |
mapper |
| Constructor and Description |
|---|
ApiHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendUrlWithQueryParameters(StringBuilder queryBuilder,
Map<String,Object> parameters)
Appends the given set of parameters to the given query string.
|
static void |
appendUrlWithTemplateParameters(StringBuilder queryBuilder,
Map<String,AbstractMap.SimpleEntry<Object,Boolean>> parameters)
Replaces template parameters in the given URL.
|
static String |
cleanUrl(StringBuilder url)
Validates and processes the given URL.
|
static LinkedHashMap<String,Object> |
deserialize(String json)
Json deserialization of the given Json string.
|
static <T> T |
deserialize(String json,
Class<T> clazz)
Json deserialization of the given Json string.
|
static <T> T |
deserialize(String json,
com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
JSON Deserialization of the given json string.
|
static <T> List<T> |
deserializeArray(String json,
Class<T[]> classArray)
JSON Deserialization of the given json string.
|
static Object |
deserializeAsObject(String json)
Json deserialization of the given Json string.
|
static boolean |
isNullOrWhiteSpace(String s)
Validates if the string is null, empty or whitespace.
|
static void |
populate(String json,
ApiException obj)
Populates an object of an ApiException subclass with the required properties.
|
static List<AbstractMap.SimpleEntry<String,Object>> |
prepareFormFields(Map<?,?> value)
Prepares Array style form fields from a given array of values.
|
static void |
removeNullValues(Map<String,?> map)
Removes null values from the given map.
|
static void |
replaceAll(StringBuilder stringBuilder,
String toReplace,
String replaceWith)
Replaces all occurrences of the given string in the string builder.
|
static String |
serialize(Object obj)
Json Serialization of a given object.
|
static String |
serialize(Object obj,
com.fasterxml.jackson.databind.JsonSerializer serializer)
Json Serialization of a given object using a specified JsonSerializer.
|
static String |
tryUrlEncode(String value,
boolean spaceAsPercentEncoded)
Tries URL encode using UTF-8.
|
public static String serialize(Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
obj - The object to serialize into Json.com.fasterxml.jackson.core.JsonProcessingException - Signals that a Json Processing Exception has occurred.public static String serialize(Object obj, com.fasterxml.jackson.databind.JsonSerializer serializer) throws com.fasterxml.jackson.core.JsonProcessingException
obj - The object to serialize into Json.serializer - The instance of JsonSerializer to use.com.fasterxml.jackson.core.JsonProcessingException - Signals that a Json Processing Exception has occurred.public static <T> T deserialize(String json, Class<T> clazz) throws IOException
T - The type of the object to deserialize intojson - The Json string to deserializeclazz - The type of the object to deserialize intoIOException - Signals if any I/O exception occured.public static LinkedHashMap<String,Object> deserialize(String json) throws IOException
json - The Json string to deserializeIOException - Signals if any I/O exception occured.public static <T> T deserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws IOException
T - The type of the object to deserialize intojson - The json string to deserializetypeReference - TypeReference of TIOException - Signals if any I/O exception occured.public static Object deserializeAsObject(String json)
json - The Json string to deserializepublic static <T> List<T> deserializeArray(String json, Class<T[]> classArray) throws IOException
T - The type of the object to deserialize intojson - The Json string to deserializeclassArray - The class of the array of objects to deserialize intoIOException - Signals if any I/O exception occured.public static void populate(String json, ApiException obj) throws IOException
json - The Json string to deserializeobj - The object to populate.IOException - Signals if any I/O exception occured.public static void appendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String,AbstractMap.SimpleEntry<Object,Boolean>> parameters)
queryBuilder - The query string builder to replace the template parametersparameters - The parameters to replace in the URLpublic static void appendUrlWithQueryParameters(StringBuilder queryBuilder, Map<String,Object> parameters)
queryBuilder - The query URL string to append the parameters.parameters - The parameters to append.public static boolean isNullOrWhiteSpace(String s)
s - The string to validate.public static void replaceAll(StringBuilder stringBuilder, String toReplace, String replaceWith)
stringBuilder - The string builder to update with replaced strings.toReplace - The string to replace in the string builder.replaceWith - The string to replace with.public static void removeNullValues(Map<String,?> map)
map - Map of values.public static String cleanUrl(StringBuilder url)
url - The given URL to process.public static List<AbstractMap.SimpleEntry<String,Object>> prepareFormFields(Map<?,?> value)
value - Value for the form fields.Copyright © 2022. All rights reserved.