Question on correct syntax for object definitions

0 views
Skip to first unread message

Peter Svensson

unread,
Sep 10, 2009, 9:08:51 AM9/10/09
to persevere...@googlegroups.com
Hi, 

I'm creating two files under WEB-INF/config/jslib/  (using 1.0rc1);

Entry.js;


Class( {
id :"Entry",
        properties :
{
                date : { type:"string" },
desc : { type:"string" },
amount :       { type:"number" },
total :       { type:"number" },
account : { "$ref": "/Account" } 
       }
});


and

Account.js;

Class( {
id :"Account",
        properties :
{
                name : { type:"string" },
holder : {"$ref": "/User"},
entries :       { type: [ "Any" ] }
  }
});


My apologies for the strange formatting. My problem is this: No matter how I try to proof-read the json-schema standard and documentation I always get the following error when I start Persevere;

2009-09-10 15:05:30.889::WARN:  Nested in java.lang.ExceptionInInitializerError:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
        at org.persvr.data.DataSourceManager.<clinit>(DataSourceManager.java:165)
        at org.persvr.data.Identification.idForString(Identification.java:48)
        at org.persvr.Persevere.load(Persevere.java:145)
...

I have tried to remove one or the other file from the directory, and I still get the same error. If I remove both Persevere starts nicely without a hitch. I think I am making some kind of very basic mistake here, but what?

Thanks!

Cheers,
PS

Dean Landolt

unread,
Sep 10, 2009, 9:57:44 AM9/10/09
to persevere...@googlegroups.com
On Thu, Sep 10, 2009 at 9:08 AM, Peter Svensson <psve...@gmail.com> wrote:
Hi, 

I'm creating two files under WEB-INF/config/jslib/  (using 1.0rc1);

Entry.js;


Class( {
id :"Entry",
        properties :
{
                date : { type:"string" },
desc : { type:"string" },
amount :       { type:"number" },
total :       { type:"number" },
account : { "$ref": "/Account" } 
       }
});


and

Account.js;

Class( {
id :"Account",
        properties :
{
                name : { type:"string" },
holder : {"$ref": "/User"},
entries :       { type: [ "Any" ] }
  }
});


Are either of these two bolded property definitions legal? That could be the source of the error casting "string" to "map".

Kris Zyp

unread,
Sep 10, 2009, 11:33:23 AM9/10/09
to persevere...@googlegroups.com
You shouldn't (and can't) use JSON referencing syntax within jslib
files. Rather you can just use direct JS references:

Class( {
id :"Entry",
properties :
{
date : { type:"string" },
desc : { type:"string" },
amount : { type:"number" },
total : { type:"number" },
account : Account
}
});

Class( {
id :"Account",
properties :
{
name : { type:"string" },
holder : User,
entries : { type: "array" }
}
});

Peter Svensson

unread,
Sep 10, 2009, 12:19:23 PM9/10/09
to persevere...@googlegroups.com
Thank you Kris!! It really should have worked. But unfortunately it didn't.
I tried to combine the two definitions into one file, so that Account was defined before Entry, but it didn't help either.
Only when I again removed both or the single file did the error go away. Could you try to add those files and see if you get the same error (same as before with String not able to be cast to Map)?

Cheers,
PS

Peter Svensson

unread,
Sep 10, 2009, 1:59:24 PM9/10/09
to persevere...@googlegroups.com
Hmm. I actually tried to re-unpack the 10.rc1 tgz and create the jslib directory again under WEB-INF/config, and again create two new files for Account.js and Entry.js, but still get the same error. However, whereas the errors sometimes refered to the files involved (i.e. Entry.js for example), I now get e reference to 

2009-09-10 19:54:39.033::WARN:  failed org.mortbay.jetty.webapp.WebAppContext@23abcc03{/,file:/home/psvensson/Downloads/persevere1.0rc1/}             

The main catalog where I unpacked it. Very odd this.

What is odd is that I the removed both files and created a new one called just 'foo.js' under WEB-INF/config/jslib/ containing this;

Class( 
{
"id" :"foo",
  "properties" :
{
    "name" : { "type":"string" }
  }
});

Not very complicated and definitely not using any referencing. And _still_ the same error. I think that there is something wrong with the docs or possibly my head at this point :) I'll go tuck in the kids and have a cup of coffee.. Over and out.

Cheers,
PS

Kris Zyp

unread,
Sep 10, 2009, 3:08:27 PM9/10/09
to persevere...@googlegroups.com
I think I see the problem, "jslib" should be under WEB-INF, not under
WEB-INF/config. So it should be WEB-INF/jslib/Account.js. Your class
definitions seem to work fine on my box (make sure that if they are in
separate files that you do require("Account") in your Entry.js file).
Kris

Peter Svensson

unread,
Sep 11, 2009, 12:12:19 AM9/11/09
to persevere...@googlegroups.com
Thank you very much, Kris. That did it. I really have to read the docs more carefully.
Also thx for the Require. 

Cheers,
PS
Reply all
Reply to author
Forward
0 new messages