public class JsonWriter extends Object
Constructor and Description |
---|
JsonWriter()
Constructor with default properties.
|
JsonWriter(int indent,
boolean spacer)
Custom constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
public JsonWriter()
public JsonWriter(int indent, boolean spacer)
indent
- number of characters indent per levelspacer
- whether to put spaces inside bracketspublic String toJson(Object item)
item
- suitable objectpublic 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 levelpublic 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 firstCopyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.