Use of reserved words in JSON structure

2009-08-10 Thread Jeff Chimene

Hi,

I'm trying to implement an API that uses two JavaScript reserved words
in a JSON structure: public and private

Is there a clever JS technique to work-around this use of the reserved
word public?

Consider the following object

{addresses : {public: [],private:[]}

The following JSNI code fails missing name after . operator:

public final native ListString getPublicAddress() /*-{
return this.addresses.public;
}-*/;

public final native void setPublicAddress(String nextValue) /*-{
if (this.addresses.public.length = 0) {
this.addresses.public = new Array();
}
this.addresses.public.push(nextValue);
}-*/;



--~--~-~--~~~---~--~~
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-Toolkit@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
-~--~~~~--~~--~--~---



Re: Use of reserved words in JSON structure

2009-08-10 Thread Jeff Chimene

On 08/10/2009 01:20 PM, Jeff Chimene wrote:
 Hi,
 
 I'm trying to implement an API that uses two JavaScript reserved words
 in a JSON structure: public and private
 
 Is there a clever JS technique to work-around this use of the reserved
 word public?
 
 Consider the following object
 
 {addresses : {public: [],private:[]}
 
 The following JSNI code fails missing name after . operator:
 
   public final native ListString getPublicAddress() /*-{
   return this.addresses.public;
   }-*/;
   
   public final native void setPublicAddress(String nextValue) /*-{
   if (this.addresses.public.length = 0) {
   this.addresses.public = new Array();
   }
   this.addresses.public.push(nextValue);
   }-*/;
 
 

Looks like this may be a Rhino problem. Here's a sample Rhino session

js x = eval(({addresses:{'public':[], 'private':[],fred:[]}}))
[object Object]

js print (x.addresses.fred)

js print (x.addresses.public)
js: stdin, line 26: missing name after . operator
js: print (x.addresses.public)
js: .^
js print (x.addresses.'public')
js print (x.addresses.public)
js: stdin, line 28: missing name after . operator
js: print (x.addresses.public)
js: ..^
js

feh.

--~--~-~--~~~---~--~~
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-Toolkit@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
-~--~~~~--~~--~--~---