Package org.astrogrid.samp
Class JsonWriter
- java.lang.Object
-
- org.astrogrid.samp.JsonWriter
-
class JsonWriter extends java.lang.Object
Outputs a SAMP object as JSON. Can do it formatted and reasonably compact.- Since:
- 25 Jul 2011
- Author:
- Mark Taylor
-
-
Constructor Summary
Constructors Constructor Description JsonWriter()
Constructor with default properties.JsonWriter(int indent, boolean spacer)
Custom constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.String
getIndent(int level)
Returns prepended whitespace.private java.lang.String
getIntroIndent(int level, char chr, boolean isPositioned)
Returns prepended whitespace containing an opener character.static void
main(java.lang.String[] args)
java.lang.String
toJson(java.lang.Object item)
Converts a SAMP data item to JSON.private void
toJson(java.lang.StringBuffer sbuf, java.lang.Object item, int level, boolean isPositioned)
Recursive method which does the work for conversion.
-
-
-
Method Detail
-
toJson
public java.lang.String toJson(java.lang.Object item)
Converts a SAMP data item to JSON.- Parameters:
item
- SAMP-friendly object- Returns:
- JSON representation
-
toJson
private void toJson(java.lang.StringBuffer sbuf, java.lang.Object item, int level, boolean isPositioned)
Recursive method which does the work for conversion. If possible, call this method withisPositioned=false
.- Parameters:
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 first
-
getIntroIndent
private java.lang.String getIntroIndent(int level, char chr, boolean isPositioned)
Returns prepended whitespace containing an opener character.- Parameters:
level
- indentation levelchr
- opener characterisPositioned
- true if output should be direct to sbuf, false if it needs a newline plus indentation first- Returns:
- string to prepend
-
getIndent
private java.lang.String getIndent(int level)
Returns prepended whitespace.- Parameters:
level
- indentation level- Returns:
- string to prepend
-
main
public static void main(java.lang.String[] args)
-
-