Class JSONUtil

java.lang.Object
com.patreonshout.utils.JSONUtil

public class JSONUtil
extends java.lang.Object
JSON Utilities class to provide helpful functions relating to JSON
  • Field Summary

    Fields
    Modifier and Type Field Description
    private static com.fasterxml.jackson.databind.ObjectMapper mapper
    mapper that helps map json strings into json objects
  • Constructor Summary

    Constructors
    Constructor Description
    JSONUtil()  
  • Method Summary

    Modifier and Type Method Description
    static org.json.simple.JSONObject convertStringToJSONObject​(java.lang.String jString)
    converts a json string into a JSONObject
    static <T> java.lang.Object getBeanFromJSON​(java.lang.String json, java.lang.Class<T> beanClass)
    Creates a class from the json variables provided in the json string

    Methods inherited from class java.lang.Object

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

    • mapper

      private static final com.fasterxml.jackson.databind.ObjectMapper mapper
      mapper that helps map json strings into json objects
  • Constructor Details

    • JSONUtil

      public JSONUtil()
  • Method Details

    • convertStringToJSONObject

      public static org.json.simple.JSONObject convertStringToJSONObject​(java.lang.String jString)
      converts a json string into a JSONObject
      Parameters:
      jString - is the json string
      Returns:
      a JSONObject created from the json string
    • getBeanFromJSON

      public static <T> java.lang.Object getBeanFromJSON​(java.lang.String json, java.lang.Class<T> beanClass)
      Creates a class from the json variables provided in the json string
      Type Parameters:
      T - is the generic typing so we can use this for multiple classes
      Parameters:
      json - is the json in string format
      beanClass - is the class we want to turn the json into
      Returns:
      an object of type T with values corresponding to the json provided