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, wait
addObject, attr
public JsonBuilder()
protected JsonBuilder(JsonBuilder parent)
public static SimpleXMLBuilder getJsonBuilder(AppContext conn)
conn
- public SimpleXMLBuilder getNested() throws java.lang.UnsupportedOperationException
SimpleXMLBuilder
SimpleXMLBuilder.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 SimpleXMLBuilder
java.lang.UnsupportedOperationException
public SimpleXMLBuilder appendParent() throws java.lang.UnsupportedOperationException
SimpleXMLBuilder
appendParent
in interface SimpleXMLBuilder
java.lang.UnsupportedOperationException
public SimpleXMLBuilder getParent()
SimpleXMLBuilder
getParent
in interface SimpleXMLBuilder
public SimpleXMLBuilder clean(java.lang.CharSequence s)
SimpleXMLBuilder
clean
in interface SimpleXMLBuilder
public SimpleXMLBuilder clean(char c)
clean
in interface SimpleXMLBuilder
public SimpleXMLBuilder clean(java.lang.Number i)
SimpleXMLBuilder
clean
in interface SimpleXMLBuilder
i
- Number to formatpublic SimpleXMLBuilder open(java.lang.String tag)
SimpleXMLBuilder
open
in interface SimpleXMLBuilder
protected void prefix()
public SimpleXMLBuilder open(java.lang.String tag, java.lang.String[][] a)
SimpleXMLBuilder
open
in interface SimpleXMLBuilder
tag
- tag to opena
- array of name,value pairspublic SimpleXMLBuilder attr(java.lang.String name, java.lang.CharSequence s)
SimpleXMLBuilder
attr
in interface SimpleXMLBuilder
name
- String attribute names
- CharSequence attribute value or null for no valuepublic SimpleXMLBuilder close()
SimpleXMLBuilder
close
in interface SimpleXMLBuilder
public java.lang.String toString()
toString
in class java.lang.Object
public boolean setEscapeUnicode(boolean escape_unicode)
SimpleXMLBuilder
setEscapeUnicode
in interface SimpleXMLBuilder