Class JSONBuilder
- java.lang.Object
-
- com.santaba.agent.groovyapi.common.JSONBuilder
-
public class JSONBuilder extends java.lang.Object
JSONBuilder for Groovy API
HOW TO USE IT.
1.JSONBuilder builder = new JSONBuilder(); builder.put("version", "1.0") .array("events") .object() .put("happenOn", "2015-07-01T22:25:24.988+08:00") .put("severity", "warn") .put("message", "This is a message") .put("custom", "This is a customer") .endObject() .endArray();
JSONBuilder builder = new JSONBuilder(); builder.put("version", "1.0") .object("object") .array("array") .put("array-value") .endArray() .put("attr", "value") .endObject();
-
-
Constructor Summary
Constructors Constructor Description JSONBuilder()
Root JSONObjectJSONBuilder(boolean isObject, JSONBuilder parent)
JSONBuilder(JSONBuilder parent)
New an JSONObject Builder
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JSONBuilder
array()
Start a new JSONArray & current object is a JSONArrayJSONBuilder
array(java.lang.String key)
Start a new JSONArrayJSONBuilder
endArray()
mean current JSONArray is ended.JSONBuilder
endObject()
This should be show up in pair with object() This meansJSONBuilder
object()
Start new JSONObject in a JSONArrayJSONBuilder
object(java.lang.String key)
Start a new JSONObject,JSONBuilder
put(java.lang.String value)
Put an value in a JSONArrayJSONBuilder
put(java.lang.String key, java.lang.Object value)
Put an new key-value in a JSONObjetjava.lang.String
toString()
java.lang.String
toString(int indentFactor)
Make a prettyprinted JSON text of this JSONArray.
-
-
-
Constructor Detail
-
JSONBuilder
public JSONBuilder()
Root JSONObject
-
JSONBuilder
public JSONBuilder(boolean isObject, JSONBuilder parent)
- Parameters:
isObject
- true means current is JSONObject, otherwise is JSONArrayparent
- current object's parent, null means current is the ROOT
-
JSONBuilder
public JSONBuilder(JSONBuilder parent)
New an JSONObject Builder- Parameters:
parent
- Parent JSONBuilder
-
-
Method Detail
-
object
public JSONBuilder object(java.lang.String key)
Start a new JSONObject,- Parameters:
key
- null means current is JSONArray, otherwise means current is JSONObject- Returns:
- a new JSONObject
-
object
public JSONBuilder object()
Start new JSONObject in a JSONArray- Returns:
- a new JSONObject
-
endObject
public JSONBuilder endObject()
This should be show up in pair with object() This means- Returns:
- current JSONObject's parent Object
-
array
public JSONBuilder array(java.lang.String key)
Start a new JSONArray- Parameters:
key
- null means current object is a JSONArray, otherwise is a JSONObject- Returns:
- a new JSONArray
-
array
public JSONBuilder array()
Start a new JSONArray & current object is a JSONArray- Returns:
- JSONBuilder object
-
endArray
public JSONBuilder endArray()
mean current JSONArray is ended.- Returns:
- current's parent object
-
put
public JSONBuilder put(java.lang.String key, java.lang.Object value)
Put an new key-value in a JSONObjet- Parameters:
key
- JSON keyvalue
- JSON value- Returns:
- JSONBuilder object
-
put
public JSONBuilder put(java.lang.String value)
Put an value in a JSONArray- Parameters:
value
- JSON value- Returns:
- JSONBuilder object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toString
public java.lang.String toString(int indentFactor)
Make a prettyprinted JSON text of this JSONArray. Warning: This method assumes that the data structure is acyclical.- Parameters:
indentFactor
- The number of spaces to add to each level of indentation.- Returns:
- a printable, displayable, transmittable representation of the
object, beginning with
[
(left bracket) and ending with]
(right bracket).
-
-