Hello John,

there are several ways to achieve this.
If you are using the XStream extension, you can take the control of the
generation by specifying a dedicated method in the resource (with this
annotation @Get("xml") ), and having a look at this page :
http://xstream.codehaus.org/alias-tutorial.html. Having said that I'm not
sure you will be able to customize the tranformation of the MAP.Entry class
for example. You can also decide to apply an XSLT transformation to the
XstreamRepresentation by wrapping it with a
org.restlet.ext.xml.TransformRepresentation.
Another way is to use either the jaxb or jibx extensions which should give
you more control.


Best regards,
Thierry Boileau

ps : here is a sample code for Xstream.
    @Get("xml")
    public Representation toRepresentation() {
        Map<String, String> map = new HashMap<String, String>();
        map.put("John", "Boston");
        map.put("Paul", "Paris");

        XstreamRepresentation<Map<String, String>> result = new
XstreamRepresentation<Map<String, String>>(
                map);
        result.getXstream().alias("users", Map.class);
        result.getXstream().alias("user", Map.Entry.class);

        return result;
    }

Hi,
>
> I've recently started to use Restlet. I have a GET method like the
> following:
>
> @Get
> public HashMap users() {
>     HashMap myUsers = getUserMap();
>     return myUsers ;
> }
>
>
> I can receive both JSON and XML data by setting the appropriate accept
> headers in my client. However I'm not happy with the data returned.
>
> I get something like this:
> <map>
>     <entry>
>         <string>John</string>
>         <string>Boston</string>
>     </entry>
>     <entry>
>         <string>Paul</string>
>         <string>Paris</string>
>     </entry>
> </map>
>
> However I really want it in this form:
>
> <users>
>     <user>
>         <name>John</name>
>         <location>Boston</location>
>     </user>
>     <user>
>         <name>Paul</name>
>         <location>Paris</location>
>     </user>
> </users>
>
>
> I assume I need to write some sort of getter to extract the data from the
> Hashmap and present it to be returned but I'm not sure how to start.
>
> Thanks for your help,
> John
>
>
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2725203

Reply via email to