Attached Object as JSON

Last modified by Fawad Ali on 2019/05/29 19:53

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

Fawad Ali

Rating
Rate!
0 Votes
LicenseGNU Lesser General Public License 2.1

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

Prerequisites & Installation Instructions

Copy the code snippet to a page and save it.

Tags:
Created by Fawad Ali on 2019/05/29 19:50
     

Get Connected