Package fmpp.models
Class JSONNode
- java.lang.Object
-
- fmpp.models.JSONNode
-
- All Implemented Interfaces:
freemarker.template.AdapterTemplateModel
,freemarker.template.TemplateModel
,freemarker.template.TemplateNodeModel
,java.io.Serializable
- Direct Known Subclasses:
JSONArrayNode
,JSONBooleanNode
,JSONNullNode
,JSONNumberNode
,JSONObjectNode
,JSONStringNode
public abstract class JSONNode extends java.lang.Object implements freemarker.template.TemplateNodeModel, freemarker.template.AdapterTemplateModel, java.io.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:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract java.lang.String
getDefaultNodeName()
Returns the name of the node if it has no explicit name.java.lang.String
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.java.lang.String
getNodeNamespace()
freemarker.template.TemplateNodeModel
getParentNode()
Returns the JSON "object" or JSON "array" that contains this value.protected static java.lang.String
nodeTypeToDefaultNodeName(java.lang.String nodeType)
Returns the FTL node name for a node that has otherwise no name.static JSONNode
wrap(java.lang.Object jsonPOJO)
protected static JSONNode
wrap(java.lang.Object obj, JSONNode parentNode, java.lang.String nodeName, boolean wrapNullAsJSONNullNode)
-
-
-
Constructor Detail
-
JSONNode
protected JSONNode(JSONNode parentNode, java.lang.String nodeName)
- 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 Detail
-
nodeTypeToDefaultNodeName
protected static java.lang.String nodeTypeToDefaultNodeName(java.lang.String nodeType)
Returns the FTL node name for a node that has otherwise no name.
-
getDefaultNodeName
protected abstract java.lang.String 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:
nodeTypeToDefaultNodeName(String)
-
getParentNode
public final freemarker.template.TemplateNodeModel getParentNode() throws freemarker.template.TemplateModelException
Returns the JSON "object" or JSON "array" that contains this value.- Specified by:
getParentNode
in interfacefreemarker.template.TemplateNodeModel
- Throws:
freemarker.template.TemplateModelException
-
getNodeName
public final java.lang.String getNodeName() throws freemarker.template.TemplateModelException
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
public final java.lang.String getNodeNamespace() throws freemarker.template.TemplateModelException
- Specified by:
getNodeNamespace
in interfacefreemarker.template.TemplateNodeModel
- Throws:
freemarker.template.TemplateModelException
-
wrap
public static JSONNode wrap(java.lang.Object jsonPOJO) throws freemarker.template.TemplateModelException
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(java.lang.Object obj, JSONNode parentNode, java.lang.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.
-
-