public class PersistorToJSONFile extends PersistorToHierarchialFile
{
"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 |
filename, ignoredFieldsForUnpickle, persistFile, reader, writerruntime| Constructor and Description |
|---|
PersistorToJSONFile(RuntimeDataInterface runtime,
java.lang.String filename) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
beforeUnpickle() |
protected void |
childBegin(java.lang.String key,
java.lang.String value)
This is called inside
PersistorToHierarchialFile.write(Persistable) to write "key"
and "value" of a child. |
protected void |
childEnd(boolean lastTag)
This is called inside
PersistorToHierarchialFile.write(Persistable) to write the
end of a child, here a newline "\n" is written. |
protected void |
containerBegin(java.lang.String className)
This is called inside
PersistorToHierarchialFile.write(Persistable) to write the begin
of a container such as:
<tagNam> for XML file
"tagName" : {\n for JSON file
|
protected void |
containerEnd(java.lang.String className)
This is called inside
PersistorToHierarchialFile.write(Persistable) to write the end
of a container such as:
</tagNam> for XML file
} for JSON file. |
protected Persistable |
doUnpickle() |
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 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
PersistorToFile.write(Persistable). |
protected void |
writeTailer(Persistable persistable)
This is called after
PersistorToFile.write(Persistable). |
getTagName, parseFiledValue, writeequals, getPersistenceName, getType, isIgnoredFiled, persist, unpersist, unpicklevalidatepublic PersistorToJSONFile(RuntimeDataInterface runtime, java.lang.String filename)
runtime - filename - protected void writeHeader(Persistable persistable) throws SAFSException, java.io.IOException
PersistorToFilePersistorToFile.write(Persistable).writeHeader in class PersistorToFileSAFSExceptionjava.io.IOExceptionprotected void writeTailer(Persistable persistable) throws SAFSException, java.io.IOException
PersistorToFilePersistorToFile.write(Persistable).writeTailer in class PersistorToFileSAFSExceptionjava.io.IOExceptionprotected void containerBegin(java.lang.String className)
throws java.io.IOException
PersistorToHierarchialFilePersistorToHierarchialFile.write(Persistable) to write the begin
of a container such as:
containerBegin in class PersistorToHierarchialFileclassName - 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.java.io.IOExceptionprotected void childBegin(java.lang.String key,
java.lang.String value)
throws java.io.IOException
PersistorToHierarchialFilePersistorToHierarchialFile.write(Persistable) to write "key"
and "value" of a child.childBegin in class PersistorToHierarchialFilekey - String, the key namevalue - String, the valuejava.io.IOExceptionprotected void childEnd(boolean lastTag)
throws java.io.IOException
PersistorToHierarchialFilePersistorToHierarchialFile.write(Persistable) to write the
end of a child, here a newline "\n" is written.childEnd in class PersistorToHierarchialFilelastTag - 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" ,java.io.IOExceptionprotected void containerEnd(java.lang.String className)
throws java.io.IOException
PersistorToHierarchialFilePersistorToHierarchialFile.write(Persistable) to write the end
of a container such as:
containerEnd in class PersistorToHierarchialFileclassName - 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.java.io.IOExceptionprotected void beforeUnpickle()
throws SAFSException,
java.io.IOException
beforeUnpickle in class PersistorToFileSAFSExceptionjava.io.IOExceptionprotected Persistable doUnpickle() throws SAFSException, java.io.IOException
doUnpickle in class PersistorToFileSAFSExceptionjava.io.IOExceptionpublic 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()
PersistorToFilestringNeedQuoted in class PersistorToFileprotected java.lang.String escape(java.lang.String value)
escape in class PersistorToFilevalue - String, the value to escapePersistorToFile.stringNeedQuoted()Copyright © SAS Institute. All Rights Reserved.