public class PersistorToJSONString extends PersistorToHierarchialString
{
"Response": {
"StatusCode": "200",
"Headers" : "{Date=Tue, 13 Dec 2016 03:32:13 GMT, Content-Length=4574, Content-Type=application/xml}",
"EntityBody" : "<?xml version=\"1.0\"?><CUSTOMERList xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <CUSTOMER xlink:href=\"http://www.thomas-bayer.com/sqlrest/CUSTOMER/0/\">0</CUSTOMER> \n</CUSTOMERList>",
"Request": {
"Method": "GET",
"Headers": "{Date=Tue, 06 Dec 2016 03:08:12 GMT, Content-Length=4574}"
}
}
}
NOTE: Be careful with the value occupying multiple lines, which should be escaped
as characters \n; the double quote " should be escaped as
\". The example is shown as above.| Modifier and Type | Field and Description |
|---|---|
(package private) org.json.JSONObject |
jsonObject |
JSON_ARRAY_BRACKET_LEFT, JSON_ARRAY_BRACKET_RIGHT, JSON_ARRAY_COMMA_SEPignoredFieldsForUnpickle, stringFormat, stringFormatReader| Constructor and Description |
|---|
PersistorToJSONString() |
PersistorToJSONString(java.io.Reader stringFormatReader) |
PersistorToJSONString(java.lang.String stringFormat) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
beforeUnpickle()
Prepare the parser with the string format of a Persistable object.
|
protected Persistable |
doUnpickle()
Convert the string format of a Persistable object to Persistable object.
|
protected java.lang.String |
escape(java.lang.String value)
Escape special characters such as value occupying multiple lines, which should be escaped
as characters \n; the double quote should be escaped as
\".
|
protected java.lang.String |
getChildBegin(java.lang.String key,
java.lang.String value,
java.lang.String classname)
This is called inside
PersistorToHierarchialString.parse(Persistable, boolean) to write "key"
and "value" of a child. |
protected java.lang.String |
getChildEnd(boolean lastChild)
This is called inside
PersistorToHierarchialString.parse(Persistable, boolean) to write the
end of a child, here a newline "\n" is written. |
protected java.lang.String |
getContainerBegin(java.lang.String className,
boolean needLeadingName)
This is called inside
PersistorToHierarchialString.parse(Persistable, boolean) to write the begin
of a container such as:
<tagNam> for XML format
"tagName" : {\n for JSON format
|
protected java.lang.String |
getContainerEnd(java.lang.String className)
This is called inside
PersistorToHierarchialString.parse(Persistable, boolean) to write the end
of a container such as:
</tagNam> for XML file
} for JSON file. |
protected boolean |
stringNeedQuoted()
If the string value needs to be quoted before writing into a kind of persistence.
JSON file requires that for string value. In JSON file, For example: "key" : "stringValue" is good "key" : stringValue is bad |
static Persistable |
unpickleParse(org.json.JSONObject body)
Try to convert JSON File to a
Persistable object.In JSON file, the special JSON key Constants.JSONConstants.PROPERTY_CLASSNAME holds the name of the class which the
JSONObject represents; the other keys are the name of the fields of that class. |
protected void |
writeHeader(Persistable persistable)
This is called before
PersistorToString.write(Persistable). |
protected void |
writeTailer(Persistable persistable)
This is called after
PersistorToString.write(Persistable). |
getTagName, parse, parseArrayField, parseFieldValuegetPersistenceName, getStringFormat, getStringFormatReader, getType, isIgnoredField, persist, setStringFormat, setStringFormatReader, unpersist, unpickle, writevalidatepublic PersistorToJSONString()
public PersistorToJSONString(java.lang.String stringFormat)
public PersistorToJSONString(java.io.Reader stringFormatReader)
protected void writeHeader(Persistable persistable) throws SAFSException
PersistorToStringPersistorToString.write(Persistable).writeHeader in class PersistorToStringSAFSExceptionprotected void writeTailer(Persistable persistable) throws SAFSException
PersistorToStringPersistorToString.write(Persistable).writeTailer in class PersistorToStringSAFSExceptionprotected void beforeUnpickle()
throws SAFSException
PersistorToStringbeforeUnpickle in class PersistorToStringSAFSExceptionprotected Persistable doUnpickle() throws SAFSException
PersistorToStringdoUnpickle in class PersistorToStringSAFSExceptionpublic static Persistable unpickleParse(org.json.JSONObject body) throws SAFSException
Persistable object.Constants.JSONConstants.PROPERTY_CLASSNAME holds the name of the class which the
JSONObject represents; the other keys are the name of the fields of that class.body - JSONObjectSAFSExceptionprotected boolean stringNeedQuoted()
PersistorToStringstringNeedQuoted in class PersistorToStringprotected java.lang.String escape(java.lang.String value)
escape in class PersistorToStringvalue - String, the value to escapePersistorToString.stringNeedQuoted()protected java.lang.String getContainerBegin(java.lang.String className,
boolean needLeadingName)
PersistorToHierarchialStringPersistorToHierarchialString.parse(Persistable, boolean) to write the begin
of a container such as:
getContainerBegin in class PersistorToHierarchialStringclassName - String, the class name of a container. This is a full class-name, which may needs to
treated to get the simple class name as the tag-name.needLeadingName - boolean, if the leading tag name is needed. For example sometimes we don't need the "tagName" for JSON format.protected java.lang.String getContainerEnd(java.lang.String className)
PersistorToHierarchialStringPersistorToHierarchialString.parse(Persistable, boolean) to write the end
of a container such as:
getContainerEnd in class PersistorToHierarchialStringclassName - String, the tag name, it is normally a container. This is a full class-name, which may needs to
treated to get the simple class name as the tag-name.protected java.lang.String getChildBegin(java.lang.String key,
java.lang.String value,
java.lang.String classname)
PersistorToHierarchialStringPersistorToHierarchialString.parse(Persistable, boolean) to write "key"
and "value" of a child.getChildBegin in class PersistorToHierarchialStringkey - String, the key namevalue - String, the valueclassname - String, the class name of this value. It is not useful with JSON format, but it is useful for XML format.protected java.lang.String getChildEnd(boolean lastChild)
PersistorToHierarchialStringPersistorToHierarchialString.parse(Persistable, boolean) to write the
end of a child, here a newline "\n" is written.getChildEnd in class PersistorToHierarchialStringlastChild - boolean, if this is the last child within the container.
it is useful for some file format, such as JSON, if this
is false (not the last child), a comma ,
needs to be added at the end as "key" : "value" ,Copyright © SAS Institute. All Rights Reserved.