Json parsing

#1

Hi,

in the last days, I have been spending several hours debugging and tracing to understand why my Wamp call handlers received their parameters as expected in some cases, and empty parameters in other cases.

I finally found out why: Jackson uses by default a deserialization strategy that relies on the JavaBeans conventions.
http://www.cowtowncoder.com/blog/archives/2011/02/entry_443.html
http://www.cowtowncoder.com/blog/archives/2011/03/entry_448.html

The problems is that my parameter classes look like:

class MyParameter {
private int cto;
public void setConnectionTimeout(int timeout) {
this.cto = timeout;
}
public int getConnectionTimeout() {
return cto;
}
}

The reason to deviate from the Beans convention is to limit the amount of data transmitted over the air. When this data structure is sent often (regularly, in arrays…), the length of the field names quickly created a big overhead…
Now the problem is that Jackson (and by extension Autobahn) expects my class to have a field called “connectionTimeout”. Since it’s not the case, I end up with an object created with the default constructor.

In one of the cases, I was using the same scheme, but the fields were public, which made it work.

As a workaround, I have now set all fields of the relevant classes as public. Using Jackson’s annotations is not an option, because the class is located in a shared library, and the other clients of this library don’t even use Jackson.

I don’t see any trivial solution for now… Has anyone a better idea ?

Thanks !

Olivier

0 Likes