Package org.opencms.jsp.util
Class CmsJspJsonWrapper
- All Implemented Interfaces:
Iterable<Object>
,Collection<Object>
Wrapper for accessing JSON in JSPs.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns the JSON text as single line, that is as compact as possible.getJson()
Returns the wrapped JSON object.Returns the wrapped JSON object.Returns the JSON text in pretty-printed and indented format.Synonym forgetPretty()
.boolean
isEmpty()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.iterator()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.void
removePath
(String path) Removes the parts from the JSON object which match the given path.static void
removePathInJson
(Object obj, List<String> pathComponents) Helper method for removing parts from a JSON object with a given path, which is already split into path components.int
size()
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.toString()
Methods inherited from class java.util.AbstractCollection
add, addAll, clear, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Constructor Details
-
CmsJspJsonWrapper
Creates a new JSON wrapper.- Parameters:
value
- the value to wrap
-
-
Method Details
-
removePathInJson
Helper method for removing parts from a JSON object with a given path, which is already split into path components. SeeremovePath(String)
for how the path works.- Parameters:
obj
- the JSON objectpathComponents
- the path components
-
getCompact
Returns the JSON text as single line, that is as compact as possible.- Returns:
- the JSON text
-
getJson
Returns the wrapped JSON object. This is an alias forgetObject()
.- Returns:
- the wrapped JSON object
- See Also:
-
getObject
Returns the wrapped JSON object. Useful in case you want to insert an existing JSON object into another JSON object.- Returns:
- the wrapped JSON object
-
getPretty
Returns the JSON text in pretty-printed and indented format.- Returns:
- the pretty-printed and indented JSON
-
getVerbose
Synonym forgetPretty()
.- Returns:
- the pretty-printed and indented JSON
- See Also:
-
isEmpty
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
isEmpty
in interfaceCollection<Object>
- Overrides:
isEmpty
in classAbstractCollection<Object>
- See Also:
-
iterator
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
iterator
in interfaceCollection<Object>
- Specified by:
iterator
in interfaceIterable<Object>
- Specified by:
iterator
in classAbstractCollection<Object>
- Returns:
- an empty Iterator in case
isEmpty()
istrue
, otherwise an Iterator that will return the String value of this wrapper exactly once. - See Also:
-
removePath
Removes the parts from the JSON object which match the given path.The path is a slash-separated sequence of path components, where each path component is either the name of a JSON field, or the wildcard '*'. The removal process locates all JSON objects matching the parent path of the given path, and then removes the entry given by the last path component from it.
- If a JSON array is encountered while descending the path, the rest of the path is processed for all elements of the array.
- If an object is encountered which does not have an entry with the same name as the next path component, it and its contents are left unchanged.
- The wildcard '* matches all keys in a JSON object.
- Parameters:
path
- the path which should be deleted
-
size
Supports the use of theempty
operator in the JSP EL by implementing the Collection interface.- Specified by:
size
in interfaceCollection<Object>
- Specified by:
size
in classAbstractCollection<Object>
- Returns:
- always returns 0.
- See Also:
-
toString
- Overrides:
toString
in classAbstractCollection<Object>
- See Also:
-