Class APIHelper

java.lang.Object
com.moesif.api.APIHelper

public class APIHelper extends Object
  • Field Details

    • mapper

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

    • APIHelper

      public APIHelper()
  • Method Details

    • getScheduler

      public static ExecutorService getScheduler()
      Singleton access to the threadpool scheduler
      Returns:
      ExecutorService instance
    • shutdown

      public static void shutdown()
      Shutdown all the threads
    • parseDate

      public static Date parseDate(String date) throws ParseException
      Parse a date from its string representation
      Parameters:
      date - ISO8601 encodede date string
      Returns:
      Parsed Date object
      Throws:
      ParseException
    • dateToString

      public static String dateToString(Date date)
      Convert a date to an ISO8601 formatted string
      Parameters:
      date - Date object to format
      Returns:
      ISO8601 formatted date string
    • serialize

      public static String serialize(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 - if error serializing JSON obj
    • deserialize

      public static <T> T deserialize(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeReference) throws 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
      typeReference - The TypeReference of the object to deserialize into
      Returns:
      The deserialized object
      Throws:
      IOException - if error deserializing
    • deserialize

      public static <T> T deserialize(String json, Class<T> typeReference) throws 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
      typeReference - The Class of the object to deserialize into
      Returns:
      The deserialized object
      Throws:
      IOException - if error deserializing
    • populate

      public static void populate(String json, APIException obj) throws IOException
      Populates an object of an APIException subclass with the required properties.
      Parameters:
      json - The json string to deserialize
      obj - The object to populate
      Throws:
      IOException - if error deserializing
    • deserialize

      public static LinkedHashMap<String,Object> deserialize(String json) throws IOException
      JSON Deserialization of the given json string.
      Parameters:
      json - The json string to deserialize
      Returns:
      The deserialized json as a Map
      Throws:
      IOException - if error deserializing
    • appendUrlWithTemplateParameters

      public static void appendUrlWithTemplateParameters(StringBuilder queryBuilder, Map<String,Object> parameters)
      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(StringBuilder queryBuilder, Map<String,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(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(StringBuilder stringBuilder, String toReplace, 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(Map<String,?> map)
      Removes null values from the given map
      Parameters:
      map - the input map
    • cleanUrl

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

      public static Map<String,Object> prepareFormFields(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
    • getVersion

      public static String getVersion()
      Get the current version of the moesifapi-java artifact
      Returns:
      Version string