I would suggest using jersey services with a custom services context
resolver.  Put the following file in the same package as your jersey
services and replace **SerializableObject** with all of your root
elements.  Then check out the getting started guide on
jersey.dev.java.net

@Provider
public abstract class ServicesContextResolver implements
ContextResolver<JAXBContext>
{
    private JAXBContext jsonContext;
    private static final Class<?>[] types =
{**SerializableObject**.class};

    public ServicesContextResolver()
    {
        try
        {
            jsonContext = new
JSONJAXBContext(JSONConfiguration.natural().build(), types);
        }
        catch (JAXBException e)
        {
            e.printStackTrace();
        }
    }

    @Override
    public JAXBContext getContext(Class<?> objectType)
    {
        return jsonContext();
    }
}

On Apr 9, 8:23 am, Sripathi Krishnan <sripathikrish...@gmail.com>
wrote:
> You need to set the HTTP header
> *addHeader("Content-Disposition","attachment; filename=some-file-name.json"*
> );
>
> --Sri
>
> On 8 April 2010 23:36, Sherry <mywacco...@gmail.com> wrote:
>
> > Hi,
> > I would like to have my application return a JSON object for
> > download.
>
> > I'm trying to simulate the behavior that happens when I access the
> > page: "http://search.twitter.com/trends/current.json?exclude=hashtags";
> > in which the Chrome browser automatically downloads a file
> > current.json . I've tried to print the JSON string into the output or
> > through a JSP but it doesn't work (I need to return this JSON file
> > into an XMLHttpRequest object).
>
> > I've copied the current.json file I downloaded from the twitter link
> > above into my WAR folder, but when I access it through Chrome it just
> > opens its contents in the browser, and I would like to be able to
> > download it, as in the twitter link.
> > Can anyone direct me how to force this download to happen?
> > Thank you
> > Sherry.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Google Web Toolkit" group.
> > To post to this group, send email to google-web-tool...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > google-web-toolkit+unsubscr...@googlegroups.com<google-web-toolkit%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/google-web-toolkit?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to