Really the best way to handle it, is with TypeHandlerFactory, which exposes addHandler();
So if you wanted to do what you're dong, you would implement a TypeHandler, that would
say, convert a Number to DatePicker.
public class NumberToDatePicker<Number, DatePicker> {
public DatePicker getConverted(Number n) {
return new DatePicker(in.longValue());
}
}
And you would then add that to TypeHandlerFactory like so:
TypeHandlerFactory.addHandler(Number.class, DatePicker.class, new NumberToDatePicker());
This of course presumes that you have an TypeHandler on the server that converts
DatePicker to a long, and you have an MVEL DataConverter on the server which converts back
from long to DatePicker on the server -- yes, this is incongruent and requires some
thought about how to unify this...
I have exposed a static method addEncodingHandler for JSONEncoder, so you can then add an
encoding handler like so:
JSONEncoder.addEncodingHandler(DatePicker.class, new TypeHandler() { public Long
getConverted(DatePicker picker) { return picker.getTime(); } });
...
You get the idea. You'll need to upgrade to trunk to get that working.
On 2010-02-05, at 11:49 AM, Kevin Jordan wrote:
Is there any easy way besides modifying JSONEncoder and
TypeDemarshallHelper to add something to convert a type for sending/receiving over the
wire? I’m wanting to do a subclass of Date for a DatePicker and want to serialize it a
String so TimeZone conversions don’t need to happen on it since it’ll default to midnight
for whatever the server timezone is. It seems as far as TypeDemarshallHelper, I can just
do a static add to org.mvel2.DataConversion, but for JSONEncoder is doesn’t seem that easy
since the handlers are added to a private Map. I assume on the client side, it’s as easy
as adding a CustomFieldSerializer
(
http://code.google.com/p/wogwt/wiki/CustomFieldSerializer)?
_______________________________________________
errai-users mailing list
errai-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/errai-users