JSON Builder

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

JSON Builder

elvanor
Hello,

I am having problems outputting the very very simple JSON string:

"someThing":"someValue"

using the Grails JSON builder.

I thought just creating a node like this:

        builder.sample
        {
                        someThing("someValue")
       }

would work but it does not. It seems inside a call only a Map is accepted !!

If I put a map this works... I tried to look at the source but I am a
newbie when it comes to groovy builder so was not able to make much
out of it.

Can someone help me? I've already managed to create JSON arrays
without much problem, the only thing I cant manage to do is this very
simple thing!!

Jean-Noel

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

Abdullah Jibaly-3
Try:

render(builder:'json') {
  sample {
    someThing("someValue")
  }
}

Works for me.

-Abdullah

On 8/7/07, Jean-Noël Rivasseau <[hidden email]> wrote:

> Hello,
>
> I am having problems outputting the very very simple JSON string:
>
> "someThing":"someValue"
>
> using the Grails JSON builder.
>
> I thought just creating a node like this:
>
>         builder.sample
>         {
>                         someThing("someValue")
>        }
>
> would work but it does not. It seems inside a call only a Map is accepted !!
>
> If I put a map this works... I tried to look at the source but I am a
> newbie when it comes to groovy builder so was not able to make much
> out of it.
>
> Can someone help me? I've already managed to create JSON arrays
> without much problem, the only thing I cant manage to do is this very
> simple thing!!
>
> Jean-Noel
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

elvanor
Hello, I am not using the builder directly in a render method, my code is like:

                StringWriter writer = new StringWriter()
               
                def builder = new grails.util.JSonBuilder(writer)
       
                builder.sample()
                {
                        someThing("someValue")
                }

And this does not work for me (exception is thrown...) Any ideas?

groovy.lang.MissingMethodException: No signature of method:
java.lang.Integer.doCall() is applicable for argument types:
(java.lang.String) values: {"someValue"}

Jean-Noel

On 8/8/07, Abdullah Jibaly <[hidden email]> wrote:

> Try:
>
> render(builder:'json') {
>   sample {
>     someThing("someValue")
>   }
> }
>
> Works for me.
>
> -Abdullah
>
> On 8/7/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello,
> >
> > I am having problems outputting the very very simple JSON string:
> >
> > "someThing":"someValue"
> >
> > using the Grails JSON builder.
> >
> > I thought just creating a node like this:
> >
> >         builder.sample
> >         {
> >                         someThing("someValue")
> >        }
> >
> > would work but it does not. It seems inside a call only a Map is accepted !!
> >
> > If I put a map this works... I tried to look at the source but I am a
> > newbie when it comes to groovy builder so was not able to make much
> > out of it.
> >
> > Can someone help me? I've already managed to create JSON arrays
> > without much problem, the only thing I cant manage to do is this very
> > simple thing!!
> >
> > Jean-Noel
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

pledbrook
On 08/08/07, Jean-Noël Rivasseau <[hidden email]> wrote:

> Hello, I am not using the builder directly in a render method, my code is like:
>
>                 StringWriter writer = new StringWriter()
>
>                 def builder = new grails.util.JSonBuilder(writer)
>
>                 builder.sample()
>                 {
>                         someThing("someValue")
>                 }
>
> And this does not work for me (exception is thrown...) Any ideas?
>
> groovy.lang.MissingMethodException: No signature of method:
> java.lang.Integer.doCall() is applicable for argument types:
> (java.lang.String) values: {"someValue"}

Have you declared a 'someThing' variable somewhere, that just happens
to have an integer value? Seems the most likely explanation given the
exception.

Cheers,

Peter

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

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

elvanor
In reply to this post by elvanor
Sorry, found the (stupid) error... It was just because someThing was
already defined as an integer before...

It works now... :)

Jean-Noel

On 8/8/07, Jean-Noël Rivasseau <[hidden email]> wrote:

> Hello, I am not using the builder directly in a render method, my code is like:
>
>                 StringWriter writer = new StringWriter()
>
>                 def builder = new grails.util.JSonBuilder(writer)
>
>                 builder.sample()
>                 {
>                         someThing("someValue")
>                 }
>
> And this does not work for me (exception is thrown...) Any ideas?
>
> groovy.lang.MissingMethodException: No signature of method:
> java.lang.Integer.doCall() is applicable for argument types:
> (java.lang.String) values: {"someValue"}
>
> Jean-Noel
>
> On 8/8/07, Abdullah Jibaly <[hidden email]> wrote:
> > Try:
> >
> > render(builder:'json') {
> >   sample {
> >     someThing("someValue")
> >   }
> > }
> >
> > Works for me.
> >
> > -Abdullah
> >
> > On 8/7/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > > Hello,
> > >
> > > I am having problems outputting the very very simple JSON string:
> > >
> > > "someThing":"someValue"
> > >
> > > using the Grails JSON builder.
> > >
> > > I thought just creating a node like this:
> > >
> > >         builder.sample
> > >         {
> > >                         someThing("someValue")
> > >        }
> > >
> > > would work but it does not. It seems inside a call only a Map is accepted !!
> > >
> > > If I put a map this works... I tried to look at the source but I am a
> > > newbie when it comes to groovy builder so was not able to make much
> > > out of it.
> > >
> > > Can someone help me? I've already managed to create JSON arrays
> > > without much problem, the only thing I cant manage to do is this very
> > > simple thing!!
> > >
> > > Jean-Noel
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe from this list please visit:
> >
> >     http://xircles.codehaus.org/manage_email
> >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

elvanor
Oops - you beat me to it Peter :)

Thanks.

PS: is there a way to still use someThing as the name of the node?

On 8/8/07, Jean-Noël Rivasseau <[hidden email]> wrote:

> Sorry, found the (stupid) error... It was just because someThing was
> already defined as an integer before...
>
> It works now... :)
>
> Jean-Noel
>
> On 8/8/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello, I am not using the builder directly in a render method, my code is like:
> >
> >                 StringWriter writer = new StringWriter()
> >
> >                 def builder = new grails.util.JSonBuilder(writer)
> >
> >                 builder.sample()
> >                 {
> >                         someThing("someValue")
> >                 }
> >
> > And this does not work for me (exception is thrown...) Any ideas?
> >
> > groovy.lang.MissingMethodException: No signature of method:
> > java.lang.Integer.doCall() is applicable for argument types:
> > (java.lang.String) values: {"someValue"}
> >
> > Jean-Noel
> >
> > On 8/8/07, Abdullah Jibaly <[hidden email]> wrote:
> > > Try:
> > >
> > > render(builder:'json') {
> > >   sample {
> > >     someThing("someValue")
> > >   }
> > > }
> > >
> > > Works for me.
> > >
> > > -Abdullah
> > >
> > > On 8/7/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > > > Hello,
> > > >
> > > > I am having problems outputting the very very simple JSON string:
> > > >
> > > > "someThing":"someValue"
> > > >
> > > > using the Grails JSON builder.
> > > >
> > > > I thought just creating a node like this:
> > > >
> > > >         builder.sample
> > > >         {
> > > >                         someThing("someValue")
> > > >        }
> > > >
> > > > would work but it does not. It seems inside a call only a Map is accepted !!
> > > >
> > > > If I put a map this works... I tried to look at the source but I am a
> > > > newbie when it comes to groovy builder so was not able to make much
> > > > out of it.
> > > >
> > > > Can someone help me? I've already managed to create JSON arrays
> > > > without much problem, the only thing I cant manage to do is this very
> > > > simple thing!!
> > > >
> > > > Jean-Noel
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe from this list please visit:
> > > >
> > > >     http://xircles.codehaus.org/manage_email
> > > >
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe from this list please visit:
> > >
> > >     http://xircles.codehaus.org/manage_email
> > >
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: JSON Builder

pledbrook
On 08/08/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> Oops - you beat me to it Peter :)
>
> Thanks.
>
> PS: is there a way to still use someThing as the name of the node?

StringWriter writer = new StringWriter()

def builder = new grails.util.JSonBuilder(writer)

builder.sample()
{
    'someThing'("someValue")
}

i.e., put the name in quotes.

Cheers,

Peter

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

    http://xircles.codehaus.org/manage_email