Package fmpp.models

Class 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
    • Field Summary

      • Fields inherited from interface freemarker.template.TemplateModel

        NOTHING
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JSONNode​(JSONNode parentNode, java.lang.String nodeName)  
    • 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 as TemplateNodeModel.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)
      Wraps a List, a Map with string keys, a String, a Number or a Boolean into a JSONNode.
      protected static JSONNode wrap​(java.lang.Object obj, JSONNode parentNode, java.lang.String nodeName, boolean wrapNullAsJSONNullNode)  
      • 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 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's null, the actual node name will be getDefaultNodeName().
    • 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.
      • 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 interface freemarker.template.TemplateNodeModel
        Throws:
        freemarker.template.TemplateModelException
      • getNodeName

        public final java.lang.String getNodeName()
                                           throws freemarker.template.TemplateModelException
        Returns the same as TemplateNodeModel.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 interface freemarker.template.TemplateNodeModel
        Throws:
        freemarker.template.TemplateModelException
      • getNodeNamespace

        public final java.lang.String getNodeNamespace()
                                                throws freemarker.template.TemplateModelException
        Specified by:
        getNodeNamespace in interface freemarker.template.TemplateNodeModel
        Throws:
        freemarker.template.TemplateModelException
      • wrap

        public static JSONNode wrap​(java.lang.Object jsonPOJO)
                             throws freemarker.template.TemplateModelException
        Wraps a List, a Map with string keys, a String, a Number or a Boolean into a JSONNode. The values in the List or Map 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 a JSONNullNode instance.
        Throws:
        freemarker.template.TemplateModelException - If obj 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 of JSONNode(JSONNode, String).
        nodeName - Same as the similar parameter of JSONNode(JSONNode, String).
        Throws:
        freemarker.template.TemplateModelException - If obj can't be wrapped into JSON node.