Extension for core...

3 views
Skip to first unread message

Rob Dawson

unread,
Oct 5, 2010, 6:45:31 PM10/5/10
to play-fr...@googlegroups.com
One of the guys on my project wrote this...

package ext;

import com.google.gson.Gson;
import play.templates.JavaExtensions;

public class JsonExtensions extends JavaExtensions {

public static String toJson(Object o) {
Gson gson = new Gson();
return gson.toJson(o);
}
}


seems like it would be something that it would make sense to go back into the main framework as an extension.

dirk

unread,
Oct 5, 2010, 8:04:39 PM10/5/10
to play-fr...@googlegroups.com
Could you explain the use case?
More specifically, how would you use this instead of using renderJSON()


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


naholyr

unread,
Oct 6, 2010, 2:35:24 AM10/6/10
to play-framework
This is to be used in templates : alert(${ myString.toJson() })

and yes it would be cool as a framework feature :-)



On 5 oct, 20:04, dirk <australiandevelo...@gmail.com> wrote:
> Could you explain the use case?
> More specifically, how would you use this instead of using renderJSON()
>
>
>
> On Wed, Oct 6, 2010 at 6:45 AM, Rob Dawson <rob...@rojotek.com> wrote:
> > One of the guys on my project wrote this...
>
> > package ext;
>
> > import com.google.gson.Gson;
> > import play.templates.JavaExtensions;
>
> > public class JsonExtensions extends JavaExtensions {
>
> >    public static String toJson(Object o) {
> >        Gson gson = new Gson();
> >        return gson.toJson(o);
> >    }
> > }
>
> > seems like it would be something that it would make sense to go back into
> > the main framework as an extension.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "play-framework" group.
> > To post to this group, send email to play-fr...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > play-framewor...@googlegroups.com<play-framework%2Bunsubscribe@go oglegroups.com>
> > .

Guillaume Bort

unread,
Oct 6, 2010, 10:05:34 AM10/6/10
to play-fr...@googlegroups.com
Yes probably. Please add this snippet to a bug report. We'll add it in
a future release.

> To unsubscribe from this group, send email to play-framewor...@googlegroups.com.


> For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
>
>

--
Guillaume Bort, http://guillaume.bort.fr

For anything work-related, use g...@zenexity.fr; for everything else,
write guillau...@gmail.com

dirk

unread,
Oct 7, 2010, 12:24:25 AM10/7/10
to play-fr...@googlegroups.com
But the method doesn't take a String, it takes an Object... so I still don't get the use case. More specifically, why would you want to output json on an HTML page?
Sorry if I'm not seeing something obvious :)

To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages