Proposal for improvement of rendering capabilities (JSON, XML, ...)

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
I had the need in my current project to get a way of serializing domain objects and maps to JSON. Although the json builder provides an elegant way of rendering json for something specific, I had do build something more generic. So I've  written a class JSON which gets constructed with an Object as ctor parameter and has a render method which serializes the Object to JSON.

My proposal is to use the groovy "as" operator to provide a neat syntax for doing such a serialization of objects to the response...

eg. in an controller-action:

render(book as JSON)
or
render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)

It has not to stop with JSON... It would also be possible to create it for XML, RSS, HTML (if it makes sense)

any opinions on that?

cheers, sigi
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
Sounds good :-)

There is something in the REST plug-in that uses method invocation in
the style of

obj.toXML()

But I do like this usage of the Groovy as keyword and it provides a
nice separation. We could place them in a package like

import grails.converters.*

obj as JSON
obj as XML
etc.

What do others think?

Cheers

On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:

> I had the need in my current project to get a way of serializing domain
> objects and maps to JSON. Although the json builder provides an elegant way
> of rendering json for something specific, I had do build something more
> generic. So I've  written a class JSON which gets constructed with an Object
> as ctor parameter and has a render method which serializes the Object to
> JSON.
>
> My proposal is to use the groovy "as" operator to provide a neat syntax for
> doing such a serialization of objects to the response...
>
> eg. in an controller-action:
>
> render(book as JSON)
> or
> render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
>
> It has not to stop with JSON... It would also be possible to create it for
> XML, RSS, HTML (if it makes sense)
>
> any opinions on that?
>
>  cheers, sigi
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
Great :) Should I submit my current work as an jira issue?

cheers

On 4/13/07, Graeme Rocher <[hidden email]> wrote:
Sounds good :-)

There is something in the REST plug-in that uses method invocation in
the style of

obj.toXML()

But I do like this usage of the Groovy as keyword and it provides a
nice separation. We could place them in a package like

import grails.converters.*

obj as JSON
obj as XML
etc.

What do others think?

Cheers

On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:

> I had the need in my current project to get a way of serializing domain
> objects and maps to JSON. Although the json builder provides an elegant way
> of rendering json for something specific, I had do build something more
> generic. So I've  written a class JSON which gets constructed with an Object
> as ctor parameter and has a render method which serializes the Object to
> JSON.
>
> My proposal is to use the groovy "as" operator to provide a neat syntax for
> doing such a serialization of objects to the response...
>
> eg. in an controller-action:
>
> render(book as JSON)
> or
> render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
>
> It has not to stop with JSON... It would also be possible to create it for
> XML, RSS, HTML (if it makes sense)
>
> any opinions on that?
>
>  cheers, sigi
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Chanwit Kaewkasi
Interesting.
Just wondering, which method needs to be overridden ?

Cheers,

Chanwit

On 13/04/07, Siegfried Puchbauer <[hidden email]> wrote:

> Great :) Should I submit my current work as an jira issue?
>
> cheers
>
>
> On 4/13/07, Graeme Rocher <[hidden email] > wrote:
> > Sounds good :-)
> >
> > There is something in the REST plug-in that uses method invocation in
> > the style of
> >
> > obj.toXML()
> >
> > But I do like this usage of the Groovy as keyword and it provides a
> > nice separation. We could place them in a package like
> >
> > import grails.converters.*
> >
> > obj as JSON
> > obj as XML
> > etc.
> >
> > What do others think?
> >
> > Cheers
> >
> > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > I had the need in my current project to get a way of serializing domain
> > > objects and maps to JSON. Although the json builder provides an elegant
> way
> > > of rendering json for something specific, I had do build something more
> > > generic. So I've  written a class JSON which gets constructed with an
> Object
> > > as ctor parameter and has a render method which serializes the Object to
> > > JSON.
> > >
> > > My proposal is to use the groovy "as" operator to provide a neat syntax
> for
> > > doing such a serialization of objects to the response...
> > >
> > > eg. in an controller-action:
> > >
> > > render(book as JSON)
> > > or
> > > render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
> > >
> > > It has not to stop with JSON... It would also be possible to create it
> for
> > > XML, RSS, HTML (if it makes sense)
> > >
> > > any opinions on that?
> > >
> > >  cheers, sigi
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>


--
Chanwit Kaewkasi
PhD Student,
Centre for Novel Computing
School of Computer Science
The University of Manchester
Oxford Road
Manchester
M13 9PL, UK

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
In reply to this post by Siegfried Puchbauer
Definitely, also consider a Grails plug-in, we can always migrate to core later

Cheers

On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:

> Great :) Should I submit my current work as an jira issue?
>
> cheers
>
>
> On 4/13/07, Graeme Rocher <[hidden email] > wrote:
> >
> > Sounds good :-)
> >
> > There is something in the REST plug-in that uses method invocation in
> > the style of
> >
> > obj.toXML()
> >
> > But I do like this usage of the Groovy as keyword and it provides a
> > nice separation. We could place them in a package like
> >
> > import grails.converters.*
> >
> > obj as JSON
> > obj as XML
> > etc.
> >
> > What do others think?
> >
> > Cheers
> >
> > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > I had the need in my current project to get a way of serializing domain
> > > objects and maps to JSON. Although the json builder provides an elegant
> way
> > > of rendering json for something specific, I had do build something more
> > > generic. So I've  written a class JSON which gets constructed with an
> Object
> > > as ctor parameter and has a render method which serializes the Object to
> > > JSON.
> > >
> > > My proposal is to use the groovy "as" operator to provide a neat syntax
> for
> > > doing such a serialization of objects to the response...
> > >
> > > eg. in an controller-action:
> > >
> > > render(book as JSON)
> > > or
> > > render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
> > >
> > > It has not to stop with JSON... It would also be possible to create it
> for
> > > XML, RSS, HTML (if it makes sense)
> > >
> > > any opinions on that?
> > >
> > >  cheers, sigi
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

D T-2
This is definitely an interesting syntax.  I'm actually wondering whether this could replace the
Codec stuff.  If not, how do we see them differing in use?

Also, would these be accessible from the views/tags/templates, as well as from the controllers?

- Daiji

--- Graeme Rocher <[hidden email]> wrote:

> Definitely, also consider a Grails plug-in, we can always migrate to core later
>
> Cheers
>
> On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > Great :) Should I submit my current work as an jira issue?
> >
> > cheers
> >
> >
> > On 4/13/07, Graeme Rocher <[hidden email] > wrote:
> > >
> > > Sounds good :-)
> > >
> > > There is something in the REST plug-in that uses method invocation in
> > > the style of
> > >
> > > obj.toXML()
> > >
> > > But I do like this usage of the Groovy as keyword and it provides a
> > > nice separation. We could place them in a package like
> > >
> > > import grails.converters.*
> > >
> > > obj as JSON
> > > obj as XML
> > > etc.
> > >
> > > What do others think?
> > >
> > > Cheers
> > >
> > > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > I had the need in my current project to get a way of serializing domain
> > > > objects and maps to JSON. Although the json builder provides an elegant
> > way
> > > > of rendering json for something specific, I had do build something more
> > > > generic. So I've  written a class JSON which gets constructed with an
> > Object
> > > > as ctor parameter and has a render method which serializes the Object to
> > > > JSON.
> > > >
> > > > My proposal is to use the groovy "as" operator to provide a neat syntax
> > for
> > > > doing such a serialization of objects to the response...
> > > >
> > > > eg. in an controller-action:
> > > >
> > > > render(book as JSON)
> > > > or
> > > > render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
> > > >
> > > > It has not to stop with JSON... It would also be possible to create it
> > for
> > > > XML, RSS, HTML (if it makes sense)
> > > >
> > > > any opinions on that?
> > > >
> > > >  cheers, sigi
> > > >
> > >
> > >
> > > --
> > > Graeme Rocher
> > > Grails Project Lead
> > > http://grails.org
> > >
> > >
> > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> >
>
>
> --
> Graeme Rocher
> Grails Project Lead
> http://grails.org
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com 

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
well i see the encoding stuff as more for encoding/decoding of data in
the sense of escaping whilst i see this proposal for conversion

We could also extend the metaclass of GPathResult in XmlSlurper so you could do

xml as MyDomainClass

Cheers

On 4/13/07, D T <[hidden email]> wrote:

> This is definitely an interesting syntax.  I'm actually wondering whether this could replace the
> Codec stuff.  If not, how do we see them differing in use?
>
> Also, would these be accessible from the views/tags/templates, as well as from the controllers?
>
> - Daiji
>
> --- Graeme Rocher <[hidden email]> wrote:
>
> > Definitely, also consider a Grails plug-in, we can always migrate to core later
> >
> > Cheers
> >
> > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > Great :) Should I submit my current work as an jira issue?
> > >
> > > cheers
> > >
> > >
> > > On 4/13/07, Graeme Rocher <[hidden email] > wrote:
> > > >
> > > > Sounds good :-)
> > > >
> > > > There is something in the REST plug-in that uses method invocation in
> > > > the style of
> > > >
> > > > obj.toXML()
> > > >
> > > > But I do like this usage of the Groovy as keyword and it provides a
> > > > nice separation. We could place them in a package like
> > > >
> > > > import grails.converters.*
> > > >
> > > > obj as JSON
> > > > obj as XML
> > > > etc.
> > > >
> > > > What do others think?
> > > >
> > > > Cheers
> > > >
> > > > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > > I had the need in my current project to get a way of serializing domain
> > > > > objects and maps to JSON. Although the json builder provides an elegant
> > > way
> > > > > of rendering json for something specific, I had do build something more
> > > > > generic. So I've  written a class JSON which gets constructed with an
> > > Object
> > > > > as ctor parameter and has a render method which serializes the Object to
> > > > > JSON.
> > > > >
> > > > > My proposal is to use the groovy "as" operator to provide a neat syntax
> > > for
> > > > > doing such a serialization of objects to the response...
> > > > >
> > > > > eg. in an controller-action:
> > > > >
> > > > > render(book as JSON)
> > > > > or
> > > > > render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
> > > > >
> > > > > It has not to stop with JSON... It would also be possible to create it
> > > for
> > > > > XML, RSS, HTML (if it makes sense)
> > > > >
> > > > > any opinions on that?
> > > > >
> > > > >  cheers, sigi
> > > > >
> > > >
> > > >
> > > > --
> > > > Graeme Rocher
> > > > Grails Project Lead
> > > > http://grails.org
> > > >
> > > >
> > > ---------------------------------------------------------------------
> > > > To unsubscribe from this list please visit:
> > > >
> > > >     http://xircles.codehaus.org/manage_email
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
Just to clarify what i mean is the encodingAs and decodeFrom methods
are on java.lang.Object and therefore apply to any data type

Whilst this syntax i see more for converting domain classes or command
objects to and from xml

Cheers

On 4/13/07, Graeme Rocher <[hidden email]> wrote:

> well i see the encoding stuff as more for encoding/decoding of data in
> the sense of escaping whilst i see this proposal for conversion
>
> We could also extend the metaclass of GPathResult in XmlSlurper so you could do
>
> xml as MyDomainClass
>
> Cheers
>
> On 4/13/07, D T <[hidden email]> wrote:
> > This is definitely an interesting syntax.  I'm actually wondering whether this could replace the
> > Codec stuff.  If not, how do we see them differing in use?
> >
> > Also, would these be accessible from the views/tags/templates, as well as from the controllers?
> >
> > - Daiji
> >
> > --- Graeme Rocher <[hidden email]> wrote:
> >
> > > Definitely, also consider a Grails plug-in, we can always migrate to core later
> > >
> > > Cheers
> > >
> > > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > Great :) Should I submit my current work as an jira issue?
> > > >
> > > > cheers
> > > >
> > > >
> > > > On 4/13/07, Graeme Rocher <[hidden email] > wrote:
> > > > >
> > > > > Sounds good :-)
> > > > >
> > > > > There is something in the REST plug-in that uses method invocation in
> > > > > the style of
> > > > >
> > > > > obj.toXML()
> > > > >
> > > > > But I do like this usage of the Groovy as keyword and it provides a
> > > > > nice separation. We could place them in a package like
> > > > >
> > > > > import grails.converters.*
> > > > >
> > > > > obj as JSON
> > > > > obj as XML
> > > > > etc.
> > > > >
> > > > > What do others think?
> > > > >
> > > > > Cheers
> > > > >
> > > > > On 4/13/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > > > > I had the need in my current project to get a way of serializing domain
> > > > > > objects and maps to JSON. Although the json builder provides an elegant
> > > > way
> > > > > > of rendering json for something specific, I had do build something more
> > > > > > generic. So I've  written a class JSON which gets constructed with an
> > > > Object
> > > > > > as ctor parameter and has a render method which serializes the Object to
> > > > > > JSON.
> > > > > >
> > > > > > My proposal is to use the groovy "as" operator to provide a neat syntax
> > > > for
> > > > > > doing such a serialization of objects to the response...
> > > > > >
> > > > > > eg. in an controller-action:
> > > > > >
> > > > > > render(book as JSON)
> > > > > > or
> > > > > > render([foo: 'bar', test: 5, book: Book.get(1)] as JSON)
> > > > > >
> > > > > > It has not to stop with JSON... It would also be possible to create it
> > > > for
> > > > > > XML, RSS, HTML (if it makes sense)
> > > > > >
> > > > > > any opinions on that?
> > > > > >
> > > > > >  cheers, sigi
> > > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Graeme Rocher
> > > > > Grails Project Lead
> > > > > http://grails.org
> > > > >
> > > > >
> > > > ---------------------------------------------------------------------
> > > > > To unsubscribe from this list please visit:
> > > > >
> > > > >     http://xircles.codehaus.org/manage_email
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Graeme Rocher
> > > Grails Project Lead
> > > http://grails.org
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> >
> > __________________________________________________
> > Do You Yahoo!?
> > Tired of spam?  Yahoo! Mail has the best spam protection around
> > http://mail.yahoo.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>
> --
> Graeme Rocher
> Grails Project Lead
> http://grails.org
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
Ok, I'll create a plugin for that ... Is it possible to override core classes in a plugin? Is it enough to place the source file in src/java (will they take precedence over the classes in the jars)?

I like the reverse approach ;-) Though it's a little bit harder to implement (for JSON, XML will be no problem with xstream)... I think I will need some assistence/advice concerning that.

On 4/13/07, Chanwit Kaewkasi < [hidden email]> wrote:
Interesting.
Just wondering, which method needs to be overridden ?

It's the asType method which is defined by the groovy jdk for java.lang.Object
 

There is still something strange I stumpled upon:
I was able to do the following without overriding any method with a metaclass for Map:

[foo: 'bar'] as JSON

It works that way I wanted it to work without changing anything... I was looking for the source of an implementation of Map (HashMap etc) in the groovy repository, but I had no luck - I didn't find it.

The same does not work for List:

['a','b','c'] as JSON --> throws an Exception

Is anyone familiar enough with groovy to know where the extension for the java.lang and java.util object extensions are implemented?

cheers, sigi
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
On 4/16/07, Siegfried Puchbauer <[hidden email]> wrote:
> Ok, I'll create a plugin for that ... Is it possible to override core
> classes in a plugin? Is it enough to place the source file in src/java (will
> they take precedence over the classes in the jars)?

What class do you want to overrride?

Cheers
Graeme

>
>  I like the reverse approach ;-) Though it's a little bit harder to
> implement (for JSON, XML will be no problem with xstream)... I think I will
> need some assistence/advice concerning that.
>
>
> > On 4/13/07, Chanwit Kaewkasi < [hidden email]> wrote:
> > Interesting.
> >
> > Just wondering, which method needs to be overridden ?
> >
>
>
>  It's the asType method which is defined by the groovy jdk for
> java.lang.Object
>
>
> There is still something strange I stumpled upon:
> I was able to do the following without overriding any method with a
> metaclass for Map:
>
> [foo: 'bar'] as JSON
>
> It works that way I wanted it to work without changing anything... I was
> looking for the source of an implementation of Map (HashMap etc) in the
> groovy repository, but I had no luck - I didn't find it.
>
> The same does not work for List:
>
> ['a','b','c'] as JSON --> throws an Exception
>
> Is anyone familiar enough with groovy to know where the extension for the
> java.lang and java.util object extensions are implemented?
>
> cheers, sigi
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod

On 4/16/07, Graeme Rocher <[hidden email]> wrote:
On 4/16/07, Siegfried Puchbauer <[hidden email]> wrote:
> Ok, I'll create a plugin for that ... Is it possible to override core
> classes in a plugin? Is it enough to place the source file in src/java (will
> they take precedence over the classes in the jars)?

What class do you want to overrride?

Cheers
Graeme

>
>  I like the reverse approach ;-) Though it's a little bit harder to
> implement (for JSON, XML will be no problem with xstream)... I think I will
> need some assistence/advice concerning that.
>
>
> > On 4/13/07, Chanwit Kaewkasi < [hidden email]> wrote:
> > Interesting.
> >
> > Just wondering, which method needs to be overridden ?
> >
>
>
>  It's the asType method which is defined by the groovy jdk for
> java.lang.Object
>
>
> There is still something strange I stumpled upon:
> I was able to do the following without overriding any method with a
> metaclass for Map:
>
> [foo: 'bar'] as JSON
>
> It works that way I wanted it to work without changing anything... I was
> looking for the source of an implementation of Map (HashMap etc) in the
> groovy repository, but I had no luck - I didn't find it.
>
> The same does not work for List:
>
> ['a','b','c'] as JSON --> throws an Exception
>
> Is anyone familiar enough with groovy to know where the extension for the
> java.lang and java.util object extensions are implemented?
>
> cheers, sigi
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

     http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
You don't need to replace the class, just write a plug-in that depends
on ControllersGrailsPlugin and then in the doWithDynamicMethods
closure override the render method:

application.controllers.metaClass.each { mc ->
   mc.render = { Obj ojb ->
       // my new render method here
  }
}

Cheers

On 4/16/07, Siegfried Puchbauer <[hidden email]> wrote:

> org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod
>
>
> On 4/16/07, Graeme Rocher < [hidden email]> wrote:
> >
> > On 4/16/07, Siegfried Puchbauer < [hidden email]> wrote:
> > > Ok, I'll create a plugin for that ... Is it possible to override core
> > > classes in a plugin? Is it enough to place the source file in src/java
> (will
> > > they take precedence over the classes in the jars)?
> >
> > What class do you want to overrride?
> >
> > Cheers
> > Graeme
> >
> > >
> > >  I like the reverse approach ;-) Though it's a little bit harder to
> > > implement (for JSON, XML will be no problem with xstream)... I think I
> will
> > > need some assistence/advice concerning that.
> > >
> > >
> > > > On 4/13/07, Chanwit Kaewkasi < [hidden email]> wrote:
> > > > Interesting.
> > > >
> > > > Just wondering, which method needs to be overridden ?
> > > >
> > >
> > >
> > >  It's the asType method which is defined by the groovy jdk for
> > > java.lang.Object
> > >
> > >
> > > There is still something strange I stumpled upon:
> > > I was able to do the following without overriding any method with a
> > > metaclass for Map:
> > >
> > > [foo: 'bar'] as JSON
> > >
> > > It works that way I wanted it to work without changing anything... I was
> > > looking for the source of an implementation of Map (HashMap etc) in the
> > > groovy repository, but I had no luck - I didn't find it.
> > >
> > > The same does not work for List:
> > >
> > > ['a','b','c'] as JSON --> throws an Exception
> > >
> > > Is anyone familiar enough with groovy to know where the extension for
> the
> > > java.lang and java.util object extensions are implemented?
> > >
> > > cheers, sigi
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >      http://xircles.codehaus.org/manage_email
> >
> >
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
perfect :-)

On 4/16/07, Graeme Rocher <[hidden email]> wrote:
You don't need to replace the class, just write a plug-in that depends
on ControllersGrailsPlugin and then in the doWithDynamicMethods
closure override the render method:

application.controllers.metaClass.each { mc ->
   mc.render = { Obj ojb ->
       // my new render method here
  }
}

Cheers

On 4/16/07, Siegfried Puchbauer <[hidden email]> wrote:

> org.codehaus.groovy.grails.web.metaclass.RenderDynamicMethod
>
>
> On 4/16/07, Graeme Rocher < [hidden email]> wrote:
> >
> > On 4/16/07, Siegfried Puchbauer < [hidden email]> wrote:
> > > Ok, I'll create a plugin for that ... Is it possible to override core
> > > classes in a plugin? Is it enough to place the source file in src/java
> (will
> > > they take precedence over the classes in the jars)?
> >
> > What class do you want to overrride?
> >
> > Cheers
> > Graeme
> >
> > >
> > >  I like the reverse approach ;-) Though it's a little bit harder to
> > > implement (for JSON, XML will be no problem with xstream)... I think I
> will
> > > need some assistence/advice concerning that.
> > >
> > >
> > > > On 4/13/07, Chanwit Kaewkasi < [hidden email]> wrote:
> > > > Interesting.
> > > >
> > > > Just wondering, which method needs to be overridden ?
> > > >
> > >
> > >
> > >  It's the asType method which is defined by the groovy jdk for
> > > java.lang.Object
> > >
> > >
> > > There is still something strange I stumpled upon:
> > > I was able to do the following without overriding any method with a
> > > metaclass for Map:
> > >
> > > [foo: 'bar'] as JSON
> > >
> > > It works that way I wanted it to work without changing anything... I was
> > > looking for the source of an implementation of Map (HashMap etc) in the
> > > groovy repository, but I had no luck - I didn't find it.
> > >
> > > The same does not work for List:
> > >
> > > ['a','b','c'] as JSON --> throws an Exception
> > >
> > > Is anyone familiar enough with groovy to know where the extension for
> the
> > > java.lang and java.util object extensions are implemented?
> > >
> > > cheers, sigi
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >      http://xircles.codehaus.org/manage_email
> >
> >
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

pledbrook
In reply to this post by Siegfried Puchbauer
> Is anyone familiar enough with groovy to know where the extension for the
> java.lang and java.util object extensions are implemented?

DefaultGroovyMethods.java

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
Thank you!

On 4/16/07, Peter Ledbrook <[hidden email]> wrote:
> Is anyone familiar enough with groovy to know where the extension for the
> java.lang and java.util object extensions are implemented?

DefaultGroovyMethods.java

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Chanwit Kaewkasi
In reply to this post by Siegfried Puchbauer
Hi,

>  I like the reverse approach ;-) Though it's a little bit harder to
> implement (for JSON, XML will be no problem with xstream)

Check out the grails-rest code, there are classes to convert
GORM-compatible collections to XML via Xstream.

Cheers,

Chanwit

--
Chanwit Kaewkasi
PhD Student,
Centre for Novel Computing
School of Computer Science
The University of Manchester
Oxford Road
Manchester
M13 9PL, UK

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
Yeah! Have seen it and its allready included in my plugin :-) Great work Chanwit!

Definitely, also consider a Grails plug-in, we can always migrate to core later

Any thoughts for a name?
grails-converters?

cheers, sigi
 


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
Grails converters sounds good, btw how are you going to handle
relationships like one-to-manys. Imo for a class Author and Book it
should do something like:

<author>
     <name>foo</name>
     <books>
            <book id="23" />
            <book id="256" />
     </books>
</author>

Is that the approach you're taking?

Cheers

On 4/18/07, Siegfried Puchbauer <[hidden email]> wrote:

> Yeah! Have seen it and its allready included in my plugin :-) Great work
> Chanwit!
>
>
> > Definitely, also consider a Grails plug-in, we can always migrate to core
> later
>
> Any thoughts for a name?
> grails-converters?
>
> cheers, sigi
>
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

Siegfried Puchbauer
I have allready thought about that and your approach seems to be the most sophisticated one. Although it is going to be a bit tricky with xstream. I'm currently focusing the json side of the plugin because I'm to heavly use it within the ext ui.

The current implementation (from auto-rest) would generate smth like:

<author>
     <name>foo</name>
     <books>
            <book>
               <id>23</id>
               <name>First Book</name>
               <isbn>12344567</isbn>
            </book>
            <book>
               <id>256</id>
               <name>Second Book</name>
               <isbn>765434567</isbn>
            </book>
     </books>
</author>

On 4/18/07, Graeme Rocher <[hidden email]> wrote:
Grails converters sounds good, btw how are you going to handle
relationships like one-to-manys. Imo for a class Author and Book it
should do something like:

<author>
     <name>foo</name>
     <books>
            <book id="23" />
            <book id="256" />
     </books>
</author>

Is that the approach you're taking?

Cheers

On 4/18/07, Siegfried Puchbauer <[hidden email]> wrote:

> Yeah! Have seen it and its allready included in my plugin :-) Great work
> Chanwit!
>
>
> > Definitely, also consider a Grails plug-in, we can always migrate to core
> later
>
> Any thoughts for a name?
> grails-converters?
>
> cheers, sigi
>
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: Proposal for improvement of rendering capabilities (JSON, XML, ...)

graemer
On 4/18/07, Siegfried Puchbauer <[hidden email]> wrote:
> I have allready thought about that and your approach seems to be the most
> sophisticated one. Although it is going to be a bit tricky with xstream. I'm
> currently focusing the json side of the plugin because I'm to heavly use it
> within the ext ui.
>
> The current implementation (from auto-rest) would generate smth like:

Hmm the problem with this approach is that it breaks with circular
relationships as you get into a infinate recursion scenario. IMO just
the ids of associations should be in the XML

Cheers
Graeme

>
> <author>
>      <name>foo</name>
>      <books>
>             <book>
>                <id>23</id>
>                <name>First Book</name>
>                <isbn>12344567</isbn>
>             </book>
>             <book>
>                 <id>256</id>
>                 <name>Second Book</name>
>                 <isbn>765434567</isbn>
>              </book>
>      </books>
> </author>
>
>
> On 4/18/07, Graeme Rocher <[hidden email] > wrote:
> >
> > Grails converters sounds good, btw how are you going to handle
> > relationships like one-to-manys. Imo for a class Author and Book it
> > should do something like:
> >
> > <author>
> >      <name>foo</name>
> >      <books>
> >             <book id="23" />
> >             <book id="256" />
> >      </books>
> > </author>
> >
> > Is that the approach you're taking?
> >
> > Cheers
> >
> > On 4/18/07, Siegfried Puchbauer <[hidden email]> wrote:
> > > Yeah! Have seen it and its allready included in my plugin :-) Great work
> > > Chanwit!
> > >
> > >
> > > > Definitely, also consider a Grails plug-in, we can always migrate to
> core
> > > later
> > >
> > > Any thoughts for a name?
> > > grails-converters?
> > >
> > > cheers, sigi
> > >
> > >
> > >
> >
> >
> > --
> > Graeme Rocher
> > Grails Project Lead
> > http://grails.org
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
>


--
Graeme Rocher
Grails Project Lead
http://grails.org

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

12