Package com.bandwidth

Class ApiHelper

java.lang.Object
com.bandwidth.ApiHelper

public class ApiHelper
extends java.lang.Object
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static com.fasterxml.jackson.databind.ObjectMapper mapper  
  • Constructor Summary

    Constructors 
    Constructor Description
    ApiHelper()  
  • Method Summary

    Modifier and Type Method Description
    static void appendUrlWithQueryParameters​(java.lang.StringBuilder queryBuilder, java.util.Map<java.lang.String,​java.lang.Object> parameters)
    Appends the given set of parameters to the given query string
    static void appendUrlWithTemplateParameters​(java.lang.StringBuilder queryBuilder, java.util.Map<java.lang.String,​java.lang.Object> parameters, boolean encode)
    Replaces template parameters in the given URL
    static java.lang.String cleanUrl​(java.lang.StringBuilder url)
    Validates and processes the given URL
    static java.util.LinkedHashMap<java.lang.String,​java.lang.Object> deserialize​(java.lang.String json)
    Json deserialization of the given Json string.
    static <T> java.util.List<T> deserialize​(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<java.util.List<T>> typeReference, java.lang.Class<T> cls, com.fasterxml.jackson.databind.JsonDeserializer<T> deserializer)
    Json deserialization of the given Json string using a specified JsonDerializer.
    static <T> T deserialize​(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference)
    JSON Deserialization of the given json string.
    static <T> T deserialize​(java.lang.String json, java.lang.Class<T> clazz)
    Json deserialization of the given Json string.
    static <T> java.util.List<T> deserializeArray​(java.lang.String json, java.lang.Class<T[]> classArray)
    JSON Deserialization of the given json string.
    static boolean isNullOrWhiteSpace​(java.lang.String s)
    Validates if the string is null, empty or whitespace
    static void populate​(java.lang.String json, ApiException obj)
    Populates an object of an ApiException subclass with the required properties.
    static java.util.List<java.util.AbstractMap.SimpleEntry<java.lang.String,​java.lang.Object>> prepareFormFields​(java.lang.Object value)
    Prepares Array style form fields from a given array of values
    static void removeNullValues​(java.util.Map<java.lang.String,​?> map)
    Removes null values from the given map
    static void replaceAll​(java.lang.StringBuilder stringBuilder, java.lang.String toReplace, java.lang.String replaceWith)
    Replaces all occurrences of the given string in the string builder
    static java.lang.String serialize​(java.lang.Object obj)
    Json Serialization of a given object.
    static java.lang.String serialize​(java.lang.Object obj, com.fasterxml.jackson.databind.JsonSerializer serializer)
    Json Serialization of a given object using a specified JsonSerializer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mapper

      public static com.fasterxml.jackson.databind.ObjectMapper mapper
  • Constructor Details

  • Method Details

    • serialize

      public static java.lang.String serialize​(java.lang.Object obj) throws com.fasterxml.jackson.core.JsonProcessingException
      Json Serialization of a given object.
      Parameters:
      obj - The object to serialize into Json
      Returns:
      The serialized Json String representation of the given object
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • serialize

      public static java.lang.String serialize​(java.lang.Object obj, com.fasterxml.jackson.databind.JsonSerializer serializer) throws com.fasterxml.jackson.core.JsonProcessingException
      Json Serialization of a given object using a specified JsonSerializer.
      Parameters:
      obj - The object to serialize into Json
      serializer - The instance of JsonSerializer to use
      Returns:
      The serialized Json string representation of the given object
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • deserialize

      public static <T> java.util.List<T> deserialize​(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<java.util.List<T>> typeReference, java.lang.Class<T> cls, com.fasterxml.jackson.databind.JsonDeserializer<T> deserializer) throws java.io.IOException
      Json deserialization of the given Json string using a specified JsonDerializer.
      Type Parameters:
      T - The type of the object to deserialize into
      Parameters:
      json - The Json string to deserialize
      cls - The class to attach the deserializer to
      deserializer - The deserializer to use
      Returns:
      The deserialized object
      Throws:
      java.io.IOException
    • deserialize

      public static <T> T deserialize​(java.lang.String json, java.lang.Class<T> clazz) throws java.io.IOException
      Json deserialization of the given Json string.
      Type Parameters:
      T - The type of the object to deserialize into
      Parameters:
      jParser - The Json parser for reading Json to deserialize
      Returns:
      The deserialized object
      Throws:
      java.io.IOException
    • deserializeArray

      public static <T> java.util.List<T> deserializeArray​(java.lang.String json, java.lang.Class<T[]> classArray) throws java.io.IOException
      JSON Deserialization of the given json string.
      Parameters:
      jParser - The json parser for reading json to deserialize
      Returns:
      The deserialized list of objects
      Throws:
      java.io.IOException
    • populate

      public static void populate​(java.lang.String json, ApiException obj) throws java.io.IOException
      Populates an object of an ApiException subclass with the required properties.
      Type Parameters:
      ApiException - The object to populate.
      Parameters:
      json - The Json string to deserialize
      Throws:
      java.io.IOException
    • deserialize

      public static java.util.LinkedHashMap<java.lang.String,​java.lang.Object> deserialize​(java.lang.String json) throws java.io.IOException
      Json deserialization of the given Json string.
      Parameters:
      json - The Json string to deserialize
      Returns:
      The deserialized Json as a Map
      Throws:
      java.io.IOException
    • deserialize

      public static <T> T deserialize​(java.lang.String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws java.io.IOException
      JSON Deserialization of the given json string.
      Type Parameters:
      T - The type of the object to deserialize into
      Parameters:
      json - The json string to deserialize
      Returns:
      The deserialized object
      Throws:
      java.io.IOException
    • appendUrlWithTemplateParameters

      public static void appendUrlWithTemplateParameters​(java.lang.StringBuilder queryBuilder, java.util.Map<java.lang.String,​java.lang.Object> parameters, boolean encode)
      Replaces template parameters in the given URL
      Parameters:
      queryBuilder - The query string builder to replace the template parameters
      parameters - The parameters to replace in the URL
    • appendUrlWithQueryParameters

      public static void appendUrlWithQueryParameters​(java.lang.StringBuilder queryBuilder, java.util.Map<java.lang.String,​java.lang.Object> parameters)
      Appends the given set of parameters to the given query string
      Parameters:
      queryBuilder - The query URL string to append the parameters
      parameters - The parameters to append
    • isNullOrWhiteSpace

      public static boolean isNullOrWhiteSpace​(java.lang.String s)
      Validates if the string is null, empty or whitespace
      Parameters:
      s - The string to validate
      Returns:
      The result of validation
    • replaceAll

      public static void replaceAll​(java.lang.StringBuilder stringBuilder, java.lang.String toReplace, java.lang.String replaceWith)
      Replaces all occurrences of the given string in the string builder
      Parameters:
      stringBuilder - The string builder to update with replaced strings
      toReplace - The string to replace in the string builder
      replaceWith - The string to replace with
    • removeNullValues

      public static void removeNullValues​(java.util.Map<java.lang.String,​?> map)
      Removes null values from the given map
      Parameters:
      map - Map of values
    • cleanUrl

      public static java.lang.String cleanUrl​(java.lang.StringBuilder url)
      Validates and processes the given URL
      Parameters:
      url - The given URL to process
      Returns:
      Pre-process URL as string
    • prepareFormFields

      public static java.util.List<java.util.AbstractMap.SimpleEntry<java.lang.String,​java.lang.Object>> prepareFormFields​(java.lang.Object value)
      Prepares Array style form fields from a given array of values
      Parameters:
      value - Value for the form fields
      Returns:
      Dictionary of form fields created from array elements