Class JsonUtils

java.lang.Object
com.bazaarvoice.jolt.JsonUtils

public class JsonUtils extends Object
Static method convenience wrappers for a JsonUtil configured with a minimal ObjectMapper. The ObjectMapper use is configured to : Allow comments in the JSON strings, Hydrates all JSON Maps into LinkedHashMaps.
  • Field Details

    • util

      private static final JsonUtil util
  • Constructor Details

    • JsonUtils

      public JsonUtils()
  • Method Details

    • customJsonUtil

      public static JsonUtil customJsonUtil(com.fasterxml.jackson.databind.ObjectMapper mapper)
      Construct a JsonUtil with a Jackson ObjectMapper that has been preconfigured with custom Modules or Mixins.
    • removeRecursive

      @Deprecated public static void removeRecursive(Object json, String keyToRemove)
      Deprecated.
      Removes a key recursively from anywhere in a JSON document. NOTE: mutates its input. Deprecated: use JoltUtils instead
      Parameters:
      json - the Jackson Object version of the JSON document (contents changed by this call)
      keyToRemove - the key to remove from the document
    • javason

      public static Map<String,Object> javason(String javason)
      Utility for test classes, so that they can inline json in a test class. Does a character level replacement of apostrophe (') with double quote ("). This means you can express a snippit of JSON without having to forward slash escape everything. This is character based, so don't have any apostrophes (') in your test data.
      Parameters:
      javason - JSON-ish string you want to turn into Maps-of-Maps
      Returns:
      Maps-of-Maps
    • getDefaultJsonUtil

      public static JsonUtil getDefaultJsonUtil()
    • jsonToObject

      public static Object jsonToObject(String json)
    • jsonToObject

      public static Object jsonToObject(String json, String charset)
    • jsonToObject

      public static Object jsonToObject(InputStream in)
    • jsonToMap

      public static Map<String,Object> jsonToMap(String json)
    • jsonToMap

      public static Map<String,Object> jsonToMap(String json, String charset)
    • jsonToMap

      public static Map<String,Object> jsonToMap(InputStream in)
    • jsonToList

      public static List<Object> jsonToList(String json)
    • jsonToList

      public static List<Object> jsonToList(String json, String charset)
    • jsonToList

      public static List<Object> jsonToList(InputStream in)
    • filepathToObject

      public static Object filepathToObject(String filePath)
    • filepathToMap

      public static Map<String,Object> filepathToMap(String filePath)
    • filepathToList

      public static List<Object> filepathToList(String filePath)
    • classpathToObject

      public static Object classpathToObject(String classPath)
    • classpathToMap

      public static Map<String,Object> classpathToMap(String classPath)
    • classpathToList

      public static List<Object> classpathToList(String classPath)
    • classpathToType

      public static <T> T classpathToType(String classPath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
    • classpathToType

      public static <T> T classpathToType(String classPath, Class<T> aClass)
    • stringToType

      public static <T> T stringToType(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
    • stringToType

      public static <T> T stringToType(String json, Class<T> aClass)
    • fileToType

      public static <T> T fileToType(String filePath, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
    • fileToType

      public static <T> T fileToType(String filePath, Class<T> aClass)
    • streamToType

      public static <T> T streamToType(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
    • streamToType

      public static <T> T streamToType(InputStream in, Class<T> aClass)
    • jsonTo

      @Deprecated public static <T> T jsonTo(String json, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Deprecated.
      Use the stringToType method instead.
    • jsonTo

      @Deprecated public static <T> T jsonTo(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
      Deprecated.
      Use the streamToType method instead.
    • toJsonString

      public static String toJsonString(Object obj)
    • toPrettyJsonString

      public static String toPrettyJsonString(Object obj)
    • cloneJson

      public static Object cloneJson(Object obj)
      Makes a deep copy of a Mapinvalid input: '<'String, Object> object by converting it to a String and then back onto stock JSON objects.
      Parameters:
      obj - object tree to copy
      Returns:
      deep copy of the incoming obj