Hi Vidar,
Vidar Ramdal schrieb:
> 2009/4/15 Felix Meschberger <[email protected]>:
>>> I'm using o.a.s.commons.json.jcr.JsonItemWriter.dump(NodeIterator,
>> I have to admit, that the JsonItemWriter is kind of strange in light of
>> the resource tree: it dumps (part of) the repository but not the
>> resource tree....
>>
>>> Writer), and I'm experiencing that it does not output any nodes.
>>> The method calls dumpSingleNode for each node in the iterator, and
>>> passes a 0 for maxRecursionLevels, which makes no sense to me.
>> This is true and desired, since this method AFAICT is intended to only
>> dump the nodes and their properties of a NodeIterator.
>
> That is the desired behaviour, yes, but that is not how it currently works.
>
> dump(NodeIterator) does not dump ANY node, regardless of recursion
> level, because the test at JsonItemWriter#134:
> recursionLevelActive(currentRecursionLevel, maxRecursionLevels) ..
> always returns false, because currentRecursionLevel == 1 and
> maxRecursionLevels == 0.
> Isn't this a bug?
Oh, didn't recognize that. Yes, I agree, this looks very much like a bug.
>
> I made a testcase:
> JsonItemWriter writer = new JsonItemWriter(null);
> MockNode node1 = new MockNode("/node1");
> MockNode node2 = new MockNode("/node2");
> final NodeIterator it = new MockNodeIterator(new Node[]{node1,
> node2});
> final StringWriter sw = new StringWriter();
> writer.dump(it, sw);
> System.out.println(sw.toString());
> This prints an empty JSON array: [].
>
> However, with the change I proposed in the previous mail:
> JsonItemWriter#76:
> - dumpSingleNode(it.nextNode(), w, 1, 0);
> + dump(it.nextNode(), w, 1, 1);
>
> ... the test prints the expected two JSON objects:
> [{"name":"node1"},{"name":"node2"}]
>
> I'd be happy to create a JIRA task and fix this, should you agree that
> this is a bug (as I suspect it is).
Yes, I agree (now that I read it correctly ;-) )
Thanks and Regards
Felix
>