public class JsonBuilder extends java.lang.Object implements SimpleXMLBuilder
SimpleXMLBuilder that builds an
equivalent JSON document.
This version has no external dependencies so has to do its own
escaping etc. A reconfigurable factory method is provided
so that alternate implementations can be included in projects
that use a 3rd party JSON library.| Modifier | Constructor and Description |
|---|---|
|
JsonBuilder() |
protected |
JsonBuilder(JsonBuilder parent) |
| Modifier and Type | Method and Description |
|---|---|
SimpleXMLBuilder |
appendParent()
Append the contents of this builder to the parent (if any).
|
SimpleXMLBuilder |
attr(java.lang.String name,
java.lang.CharSequence s)
Add an attribute.
|
SimpleXMLBuilder |
clean(char c) |
SimpleXMLBuilder |
clean(java.lang.CharSequence s)
append text to the document escaping any characters that might be interpreted as XML markup.
|
SimpleXMLBuilder |
clean(java.lang.Number i)
Append text representation of the number
|
SimpleXMLBuilder |
close()
close the last opened tag.
|
static SimpleXMLBuilder |
getJsonBuilder(AppContext conn)
static factory method to allow implementations to be replaced.
|
SimpleXMLBuilder |
getNested()
Get a new SimpleXMLBuilder of the same type as this object.
|
SimpleXMLBuilder |
getParent()
Get the parent object.
|
SimpleXMLBuilder |
open(java.lang.String tag)
open a tag
|
SimpleXMLBuilder |
open(java.lang.String tag,
java.lang.String[][] a)
open a tag with attributes.
|
protected void |
prefix() |
boolean |
setEscapeUnicode(boolean escape_unicode)
Should high code-point unicode characters be escaped to
avoid charset problems.
|
java.lang.String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitaddObject, attrpublic JsonBuilder()
protected JsonBuilder(JsonBuilder parent)
public static SimpleXMLBuilder getJsonBuilder(AppContext conn)
conn - public SimpleXMLBuilder getNested() throws java.lang.UnsupportedOperationException
SimpleXMLBuilderSimpleXMLBuilder.appendParent() method.
The calling code need only hold a reference to the current builder as the
SimpleXMLBuilder.appendParent() method returns the parent.getNested in interface SimpleXMLBuilderjava.lang.UnsupportedOperationExceptionpublic SimpleXMLBuilder appendParent() throws java.lang.UnsupportedOperationException
SimpleXMLBuilderappendParent in interface SimpleXMLBuilderjava.lang.UnsupportedOperationExceptionpublic SimpleXMLBuilder getParent()
SimpleXMLBuildergetParent in interface SimpleXMLBuilderpublic SimpleXMLBuilder clean(java.lang.CharSequence s)
SimpleXMLBuilderclean in interface SimpleXMLBuilderpublic SimpleXMLBuilder clean(char c)
clean in interface SimpleXMLBuilderpublic SimpleXMLBuilder clean(java.lang.Number i)
SimpleXMLBuilderclean in interface SimpleXMLBuilderi - Number to formatpublic SimpleXMLBuilder open(java.lang.String tag)
SimpleXMLBuilderopen in interface SimpleXMLBuilderprotected void prefix()
public SimpleXMLBuilder open(java.lang.String tag, java.lang.String[][] a)
SimpleXMLBuilderopen in interface SimpleXMLBuildertag - tag to opena - array of name,value pairspublic SimpleXMLBuilder attr(java.lang.String name, java.lang.CharSequence s)
SimpleXMLBuilderattr in interface SimpleXMLBuildername - String attribute names - CharSequence attribute value or null for no valuepublic SimpleXMLBuilder close()
SimpleXMLBuilderclose in interface SimpleXMLBuilderpublic java.lang.String toString()
toString in class java.lang.Objectpublic boolean setEscapeUnicode(boolean escape_unicode)
SimpleXMLBuildersetEscapeUnicode in interface SimpleXMLBuilder