|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.ttools.taplint.JsonWriter
public class JsonWriter
Outputs an object as JSON. Classes List, Map, Number and Boolean are recognised. Arrays are not. If there is a non-string where a string is required, it's just forced to a string by calling its toString method.
Constructor Summary | |
---|---|
JsonWriter()
Constructor with default properties. |
|
JsonWriter(int indent,
boolean spacer)
Custom constructor. |
Method Summary | |
---|---|
String |
getIndent(int level)
Returns prepended whitespace. |
String |
jsonPair(String key,
Object value,
int level,
boolean isPositioned)
Serialises a key-value pair to JSON. |
String |
toJson(Object item)
Converts an item to JSON. |
void |
toJson(StringBuffer sbuf,
Object item,
int level,
boolean isPositioned)
Recursive method which does the work for conversion. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public JsonWriter()
public JsonWriter(int indent, boolean spacer)
indent
- number of characters indent per levelspacer
- whether to put spaces inside bracketsMethod Detail |
---|
public String toJson(Object item)
item
- suitable object
public void toJson(StringBuffer sbuf, Object item, int level, boolean isPositioned)
isPositioned=false
.
sbuf
- string buffer to append result toitem
- object to convertlevel
- current indentation levelisPositioned
- true if output should be direct to sbuf,
false if it needs a newline plus indentation firstpublic String getIndent(int level)
level
- indentation level
public String jsonPair(String key, Object value, int level, boolean isPositioned)
key
- key stringvalue
- value objectlevel
- indentation levelisPositioned
- true if output should be direct to sbuf,
false if it needs a newline plus indentation first
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |