Attached Object as JSON

Version 3.1 by Fawad Ali on 2019/05/29 19:53

cogGet the properties of an object attached to a page as JSON
Type
Category
Developed by

Fawad Ali

Rating
0 Votes
LicenseGNU 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}}

Make sure to have an object of type XWiki.StyleSheetExtension attached to the page

Tags:
     

Get Connected