some questions on jsonizer

25 views
Skip to first unread message

rzorzorzo

unread,
Jun 6, 2007, 5:14:07 PM6/6/07
to GWT Jsonizer
hello,

i am trying the following:

class MyGrid extends FlexTable
....

interface MyGridJsonizer extends Jsonizer

public String toJsonString(MyGrid g)
{
final MyGridJsonizer jsonizer = (MyJsonizer)
GWT.create(MyJsonizer.class);
return jsonizer.asString(g);
}

In hosted mode I am getting the following error:

[ERROR] Errors in 'transient source for
com.google.gwt.user.client.ui.__HTMLTableJsonizer_impl__'
[ERROR] Line 5: Cannot instantiate the type HTMLTable

HTMLTable is in my classpath since the gwt-user.jar is.

Is this an issue with inheritence ? do I have to define a Jsonizer
interface for each super class ?
Do Jsonizer interfaces have to be in the same package as the classes
themselves ?
What do I have ot do to solve this issue ?

- Ron

Andrés Testi

unread,
Jun 6, 2007, 5:21:21 PM6/6/07
to GWT Jsonizer
The Jsonizer Generator creates a Jsonizer implementation for each
class in the inheritance tree. This error is raised because FlexTable
class is defined in a package contained in an external jar. I will try
to fix this error in the next update. Thank you for your feeback!

rzorzorzo

unread,
Jun 6, 2007, 9:47:43 PM6/6/07
to GWT Jsonizer
Andres,

thanks.

while testing i further found the following issues:

1. In the example it should be
RootPanel.get("slot1").add(searchButton); the slot names are wrong.

2. The following code throws an error although it should not:

Person p = new Person();
PersonJsonizer jsonizer =
(PersonJsonizer)GWT.create(PersonJsonizer.class);
String t = jsonizer.asString(p);

p = (Person) JsonizerParser.parse(jsonizer, t);

I have been able to follow this to:

BeanJsonizer:

if(!jsonizer.containsRequiredProperties(values))

returning false.

3. I have the following questions/suggestions:

Why do you require the interface PersonJsonizer ? Would it not be
enough to have Person implement some marker interface for example
"Jsonizable" which would indicate to the Generator that this class has
to be processed ? this interface would be sufficient to trigger the
generator.

Why not put in the json object a property javaClass : <full java class
name> ?
This will avoid having to know in advance which jsonizer is required.
It would also enable working with java json-rpc (which sets this
property) and reduce the call to : JsonizerParser.parse(t); the
correct jsonizer could be found within the parse method by reading
this property.

- Ron

Andrés Testi

unread,
Jun 8, 2007, 2:40:50 PM6/8/07
to GWT Jsonizer
Ron:

I know the need of include the class name in the JSON object, but the
jsonizer was first designed to support generic and plain JSON. I'm
currently developing a new version of the API wich supports several
JSON variants.
Using a Jsonizable interface for bean demarcation also requires
another interface to dejsonize beans. I'm thinking in a Jsonizer
refatorization to avoid these troubles.

Reply all
Reply to author
Forward
0 new messages