org.apache.hcatalog.templeton
Class JsonBuilder

Object
  extended by JsonBuilder

public class JsonBuilder
extends Object

Helper class to build new json objects with new top level properties. Only add non-null entries.


Method Summary
 Response build()
          Turn the map back to response object.
 String buildJson()
          Turn the map back to json.
 Response buildResponse()
          Turn the map back to response object.
 Response buildResponse(int status)
          Turn the map back to response object.
static JsonBuilder create()
          Create a new map object.
static JsonBuilder create(String json)
          Create a new map object from the existing json.
static JsonBuilder createError(String msg, int code)
          Create a new map error object.
 Map getMap()
          Get the underlying map.
static boolean isError(Map obj)
          Check if this is an error doc.
 boolean isset()
          Is the object non-empty?
static Map jsonToMap(String json)
          Convert a json string to a Map.
static String mapToJson(Object obj)
          Convert a map to a json string.
 JsonBuilder put(String name, Object val)
          Add a non-null value to the map.
 JsonBuilder remove(String name)
          Remove a value from the map.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

create

public static JsonBuilder create(String json)
                          throws IOException
Create a new map object from the existing json.

Throws:
IOException

create

public static JsonBuilder create()
                          throws IOException
Create a new map object.

Throws:
IOException

createError

public static JsonBuilder createError(String msg,
                                      int code)
                               throws IOException
Create a new map error object.

Throws:
IOException

put

public JsonBuilder put(String name,
                       Object val)
Add a non-null value to the map.


remove

public JsonBuilder remove(String name)
Remove a value from the map.


getMap

public Map getMap()
Get the underlying map.


build

public Response build()
Turn the map back to response object.


buildJson

public String buildJson()
                 throws IOException
Turn the map back to json.

Throws:
IOException

buildResponse

public Response buildResponse()
Turn the map back to response object.


buildResponse

public Response buildResponse(int status)
Turn the map back to response object.


isset

public boolean isset()
Is the object non-empty?


isError

public static boolean isError(Map obj)
Check if this is an error doc.


jsonToMap

public static Map jsonToMap(String json)
                     throws IOException
Convert a json string to a Map.

Throws:
IOException

mapToJson

public static String mapToJson(Object obj)
                        throws IOException
Convert a map to a json string.

Throws:
IOException