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 String
Returns the name of the node if it has no explicit name.final String
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.final String
final freemarker.template.TemplateNodeModel
Returns the JSON "object" or JSON "array" that contains this value.protected static String
nodeTypeToDefaultNodeName
(String nodeType) Returns the FTL node name for a node that has otherwise no name.static JSONNode
protected static JSONNode
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface freemarker.template.AdapterTemplateModel
getAdaptedObject
Methods 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:
getParentNode
in 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:
getNodeName
in interfacefreemarker.template.TemplateNodeModel
- Throws:
freemarker.template.TemplateModelException
-
getNodeNamespace
- Specified by:
getNodeNamespace
in interfacefreemarker.template.TemplateNodeModel
- Throws:
freemarker.template.TemplateModelException
-
wrap
Wraps aList
, aMap
with string keys, aString
, aNumber
or aBoolean
into aJSONNode
. The values in theList
orMap
must 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
null
for JSON null values, not aJSONNullNode
instance. - Throws:
freemarker.template.TemplateModelException
- Ifobj
can'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
- Ifobj
can't be wrapped into JSON node.
-