Get the properties of an object attached to a page as JSON |
Type | |
Category | |
Developed by | |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Suppose we have an object of class XWiki.StyleSheetExtension and we want to get all of the properties in JSON.
Here is how we do it.
{{velocity}}
## Get the normal object
#set ($obj = $doc.getObject('XWiki.StyleSheetExtension'))
## Get the XWiki BaseObject from the normal object
#set ($baseObj = $obj.getXWikiObject())
## Get the Map of the object properties
#set ($objMap = $baseObj.getCustomMappingMap())
## Now that we have the Map, we can simply convert it to JSON using $jsontool
#set ($objJSON = $jsontool.serialize($objMap))
## Output the JSON
$objJSON
{{/velocity}}
## Get the normal object
#set ($obj = $doc.getObject('XWiki.StyleSheetExtension'))
## Get the XWiki BaseObject from the normal object
#set ($baseObj = $obj.getXWikiObject())
## Get the Map of the object properties
#set ($objMap = $baseObj.getCustomMappingMap())
## Now that we have the Map, we can simply convert it to JSON using $jsontool
#set ($objJSON = $jsontool.serialize($objMap))
## Output the JSON
$objJSON
{{/velocity}}
Make sure to have an object of type XWiki.StyleSheetExtension attached to the page