com.bazaarvoice.jolt
Class JsonUtils

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

public class JsonUtils
extends Object


Constructor Summary
JsonUtils()
           
 
Method Summary
static Object cloneJson(Object json)
           
static Map<String,Object> javason(String javason)
          Utility for test classes, so that they can inline json in a test class.
static
<T> T
jsonTo(InputStream in, com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
           
static Map<String,Object> jsonToMap(InputStream in)
           
static Map<String,Object> jsonToMap(String json)
           
static Object jsonToObject(InputStream in)
           
static Object jsonToObject(String json)
           
static void removeRecursive(Object json, String keyToRemove)
          Removes a key recursively from anywhere in a JSON document.
static String toJsonString(Object map)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JsonUtils

public JsonUtils()
Method Detail

cloneJson

public static Object cloneJson(Object json)

removeRecursive

public static void removeRecursive(Object json,
                                   String keyToRemove)
Removes a key recursively from anywhere in a JSON document. NOTE: mutates its input.

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)
                                  throws IOException
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
Throws:
IOException

jsonToMap

public static Map<String,Object> jsonToMap(String json)
                                    throws IOException
Throws:
IOException

jsonToObject

public static Object jsonToObject(String json)
                           throws IOException
Throws:
IOException

jsonToObject

public static Object jsonToObject(InputStream in)
                           throws IOException
Throws:
IOException

jsonToMap

public static Map<String,Object> jsonToMap(InputStream in)
                                    throws IOException
Throws:
IOException

jsonTo

public static <T> T jsonTo(InputStream in,
                           com.fasterxml.jackson.core.type.TypeReference<T> typeRef)
                throws IOException
Throws:
IOException

toJsonString

public static String toJsonString(Object map)
                           throws IOException
Throws:
IOException


Copyright © 2013. All Rights Reserved.