Hi Danilo, On Wed, May 28, 2014 at 4:19 AM, Danilo Amaral de Oliveira <danilo.olive...@energisa.com.br> wrote: > Hello Marius, > > I could make the webservice and PoC works but I am not using the method > $jsontool.serialize. >
> What is the impact if I not use this serialize method? $jsontool.serialize brings two important advantages: (1) No need to manually escape the values you put in your JSON. Otherwise you need to write something like: 'key1': '$escapetool.json($value1)', 'key2': '$escapetool.json($value2)', ... which is error prone. We used to generate the live table results this way and we forgot to escape a few values causing important bugs. (2) It's way easier to customize/modify the Java object before serializing it than customizing the code that generates the JSON string. Take this example: { totalCount: 32, rows: [ {id: 'foo', name:'Foo Abc', age: 29}, {id: 'bar', name: 'Bar Xyz', age: 17}, ... ] } Now, imagine that at some point you'll have to add a new property per row, but just for one use case. You should not modify the default JSON. You just need to extend it somehow. If you build the JSON in memory then there's no problem, you can write: #foreach ($row in $jsonObject.rows) #set ($row.additionalProperty = 'some value') #end just before serializing the $jsonObject. In other words you can reuse entirely the code that generates the default JSON. While in you case, you'd have to rewrite some of the Velocity macros that 'print' the JSON, duplicating code, which is a maintenance hell. Hope this convinces you to use $jsontool.serialize() :) Marius > > Ps.: I have updated the documentation. > http://dev.xwiki.org/xwiki/bin/view/Drafts/XWikiJSONWebServiceKickStart > > Thanks. > > Danilo > > > > Grupo Energisa > Danilo Oliveira > Analista Suporte Aplicacao TI - DPTO CORP. DE INFRAESTR. TI > e-mail: danilo.olive...@energisa.com.br | tel: (32) 3429-6342 | cel: (32) > 8452-9478 > > Esta mensagem contém informação confidencial. Se você a recebeu por engano, > não divulgue ou copie seu conteúdo. Por favor, avise ao remetente > imediatamente e apague-a do computador. > Privileged and confidential. If this message has been received by mistake, do > not disclose or copy its contents. Please notify sender and delete > immediately. > > > -----Mensagem original----- > De: users [mailto:users-boun...@xwiki.org] Em nome de Marius Dumitru Florea > Enviada em: terça-feira, 20 de maio de 2014 08:14 > Para: XWiki Users > Assunto: Re: [xwiki-users] Spatial Map Extension > > On Mon, May 19, 2014 at 10:20 PM, Danilo Amaral de Oliveira > <danilo.olive...@energisa.com.br> wrote: >> Hello People, >> >> We are planning to develop an extension that will link and show the >> documents of a specific wiki spacially allowing the user explore the page >> dynamically. The idea is similar to the "Just map it" extension. >> >> Our first step was to look some javascript framework available to draw the >> relationships that could work for us and we came to conclusion that the >> sigma.js or d3.js will work fine... >> But, I am worried with the data connection, how can I parse the data from >> the DB to the extension dynamically? >> > >> Do you think the kind of webservice bellow could work? >> dev.xwiki.org/xwiki/bin/view/Drafts/XWikiJSONWebServiceKickStart > > The direction is ok, but: > > * you should use the 'get' action instead of 'view' to access the webservice: > > $xwiki.getURL('Main.WebService', 'get', $escapetool.url({ > 'outputSyntax': 'plain', > 'limit': 10 > })) > > * the webservice should build the JSON in memory using plain Java objects > (maps, lists, strings, numbers, boolean) and then serialize it. In Velocity > you can use: > > $jsontool.serialize({ > 'foo': [1, 2, 3], > 'bar': { > 'color': 'red', > enabled: true > }, > 'name': 'XWiki' > }) > > For writing the webservice I would start with Velocity and then move to > Groovy but only if really needed. > > Hope this helps, > Marius > >> >> Thank you! >> >> >> Grupo Energisa >> Danilo Oliveira >> Analista Suporte Aplicacao TI - DPTO CORP. DE INFRAESTR. TI >> e-mail: danilo.olive...@energisa.com.br | tel: (32) 3429-6342 | cel: >> (32) 8452-9478 >> >> Esta mensagem contém informação confidencial. Se você a recebeu por engano, >> não divulgue ou copie seu conteúdo. Por favor, avise ao remetente >> imediatamente e apague-a do computador. >> Privileged and confidential. If this message has been received by mistake, >> do not disclose or copy its contents. Please notify sender and delete >> immediately. >> >> >> _______________________________________________ >> users mailing list >> users@xwiki.org >> http://lists.xwiki.org/mailman/listinfo/users > _______________________________________________ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users > _______________________________________________ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users