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, writer
runtime
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, write
equals, getPersistenceName, getType, isIgnoredFiled, persist, unpersist, unpickle
validate
public PersistorToJSONFile(RuntimeDataInterface runtime, java.lang.String filename)
runtime
- filename
- protected void writeHeader(Persistable persistable) throws SAFSException, java.io.IOException
PersistorToFile
PersistorToFile.write(Persistable)
.writeHeader
in class PersistorToFile
SAFSException
java.io.IOException
protected void writeTailer(Persistable persistable) throws SAFSException, java.io.IOException
PersistorToFile
PersistorToFile.write(Persistable)
.writeTailer
in class PersistorToFile
SAFSException
java.io.IOException
protected void containerBegin(java.lang.String className) throws java.io.IOException
PersistorToHierarchialFile
PersistorToHierarchialFile.write(Persistable)
to write the begin
of a container such as:
containerBegin
in class PersistorToHierarchialFile
className
- 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.IOException
protected void childBegin(java.lang.String key, java.lang.String value) throws java.io.IOException
PersistorToHierarchialFile
PersistorToHierarchialFile.write(Persistable)
to write "key"
and "value" of a child.childBegin
in class PersistorToHierarchialFile
key
- String, the key namevalue
- String, the valuejava.io.IOException
protected void childEnd(boolean lastTag) throws java.io.IOException
PersistorToHierarchialFile
PersistorToHierarchialFile.write(Persistable)
to write the
end of a child, here a newline "\n" is written.childEnd
in class PersistorToHierarchialFile
lastTag
- 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.IOException
protected void containerEnd(java.lang.String className) throws java.io.IOException
PersistorToHierarchialFile
PersistorToHierarchialFile.write(Persistable)
to write the end
of a container such as:
containerEnd
in class PersistorToHierarchialFile
className
- 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.IOException
protected void beforeUnpickle() throws SAFSException, java.io.IOException
beforeUnpickle
in class PersistorToFile
SAFSException
java.io.IOException
protected Persistable doUnpickle() throws SAFSException, java.io.IOException
doUnpickle
in class PersistorToFile
SAFSException
java.io.IOException
public 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
- JSONObjectSAFSException
protected boolean stringNeedQuoted()
PersistorToFile
stringNeedQuoted
in class PersistorToFile
protected java.lang.String escape(java.lang.String value)
escape
in class PersistorToFile
value
- String, the value to escapePersistorToFile.stringNeedQuoted()
Copyright © SAS Institute. All Rights Reserved.