Package fmpp.models
Class JSONNode
java.lang.Object
fmpp.models.JSONNode
- All Implemented Interfaces:
freemarker.template.AdapterTemplateModel,freemarker.template.TemplateModel,freemarker.template.TemplateNodeModel,Serializable
- Direct Known Subclasses:
JSONArrayNode,JSONBooleanNode,JSONNullNode,JSONNumberNode,JSONObjectNode,JSONStringNode
public abstract class JSONNode
extends Object
implements freemarker.template.TemplateNodeModel, freemarker.template.AdapterTemplateModel, Serializable
Node in a hierarchy of JSON values. See http://www.json.org/ for JSON types; each has its own subclass.
JSON "object" and "array" values are the non-leafs in the tree.
- See Also:
-
Field Summary
Fields inherited from interface freemarker.template.TemplateModel
NOTHING -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract StringReturns the name of the node if it has no explicit name.final StringReturns the same asTemplateNodeModel.getNodeType(), except when the node is the value in a key-value pair in a JSON object, in which case it returns the key value.final Stringfinal freemarker.template.TemplateNodeModelReturns the JSON "object" or JSON "array" that contains this value.protected static StringnodeTypeToDefaultNodeName(String nodeType) Returns the FTL node name for a node that has otherwise no name.static JSONNodeprotected static JSONNodeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface freemarker.template.AdapterTemplateModel
getAdaptedObjectMethods inherited from interface freemarker.template.TemplateNodeModel
getChildNodes, getNodeType
-
Constructor Details
-
JSONNode
- Parameters:
parentNode- the JSON "object" or JSON "array" that contains this value.nodeName-null, unless this is the value in a key-value pair, in which case it's the key. When it'snull, the actual node name will begetDefaultNodeName().
-
-
Method Details
-
nodeTypeToDefaultNodeName
Returns the FTL node name for a node that has otherwise no name. -
getDefaultNodeName
Returns the name of the node if it has no explicit name. This is normally called by theJSONNode(JSONNode, String)constructor if its second argument isnull.- See Also:
-
getParentNode
public final freemarker.template.TemplateNodeModel getParentNode() throws freemarker.template.TemplateModelExceptionReturns the JSON "object" or JSON "array" that contains this value.- Specified by:
getParentNodein interfacefreemarker.template.TemplateNodeModel- Throws:
freemarker.template.TemplateModelException
-
getNodeName
Returns the same asTemplateNodeModel.getNodeType(), except when the node is the value in a key-value pair in a JSON object, in which case it returns the key value.- Specified by:
getNodeNamein interfacefreemarker.template.TemplateNodeModel- Throws:
freemarker.template.TemplateModelException
-
getNodeNamespace
- Specified by:
getNodeNamespacein interfacefreemarker.template.TemplateNodeModel- Throws:
freemarker.template.TemplateModelException
-
wrap
Wraps aList, aMapwith string keys, aString, aNumberor aBooleaninto aJSONNode. The values in theListorMapmust be also be one of the previously listed types. The resulting object is NOT thread safe. Also, the wrapped objects shouldn't be changed after the wrapping. The wrapping of the contained values is possibly lazy.- Returns:
- The wrapped value; note the this will return
nullfor JSON null values, not aJSONNullNodeinstance. - Throws:
freemarker.template.TemplateModelException- Ifobjcan't be wrapped into JSON node.
-
wrap
protected static JSONNode wrap(Object obj, JSONNode parentNode, String nodeName, boolean wrapNullAsJSONNullNode) throws freemarker.template.TemplateModelException - Parameters:
parentNode- Same as the similar parameter ofJSONNode(JSONNode, String).nodeName- Same as the similar parameter ofJSONNode(JSONNode, String).- Throws:
freemarker.template.TemplateModelException- Ifobjcan't be wrapped into JSON node.
-