I have a question. I'm looking into adding some information needed by
the JCR browser to the JSON rendering. What I really need to do is add
at least the property type (PropertyType.String, etc.) and I'd assume we
want to pass on other traits found in the PropertyDefinition
(isMandatory(), isProtected(), isAutoCreated(), etc.).
The problem is, though, when I look at the JSON output, properties of a
node are just key-value pairs. In order to add the other information, a
property needs to be an object in its own right.
So I had a look at the code to change this and I noticed that we have:
/** Dump given property in JSON */
public void dump(Property p, Writer w) throws JSONException,
ValueFormatException, RepositoryException {
final JSONWriter jw = new JSONWriter(w);
jw.object();
writeProperty(jw, p);
jw.endObject();
}
Which would be what I'd want (each property appears to be an object in
this code), but what comes out was more likely generated by:
/** Dump given node in JSON, optionally recursing into its child
nodes */
protected void dump(Node node, JSONWriter w, int
currentRecursionLevel,
int maxRecursionLevels) throws RepositoryException,
JSONException {
w.object();
PropertyIterator props = node.getProperties();
// the node's actual properties
while (props.hasNext()) {
Property prop = props.nextProperty();
if (propertyNamesToIgnore != null
&& propertyNamesToIgnore.contains(prop.getName())) {
continue;
}
writeProperty(w, prop);
}
// the child nodes
if (recursionLevelActive(currentRecursionLevel,
maxRecursionLevels)) {
final NodeIterator children = node.getNodes();
while (children.hasNext()) {
final Node n = children.nextNode();
dumpSingleNode(n, w, currentRecursionLevel,
maxRecursionLevels);
}
}
w.endObject();
}
I haven't debugged, but I definitely know that the in the output,
properties are not objects but simple key-value pairs.
Any advice?
PS: Sorry for the formatting, but I only have Outlook available to me
and I have never been able to get it right :-(
Cheers,
Craig