Hi
all,
After
upgrading our GWT library to 1.6.4 (it works just fine by the way), I was
finally been able to make transparent bean serialization work between Restlet/GWT
and server-side Restlet!
There
was a serialization policy issue that was easy to fix but then I hit issues on
the client-side to obtain a valid serializer instance. Here is the trick: this
serializer is generated by GWT at compilation time using the deferred binding
mechanism but only for RPC RemoteService instances and the related object
classes.
So,
it works with one constraint: you need to have a RemoteService defined that
uses all the objects you intend to serialize/deserialize RESTfully. I’ve
tested both serialization and deserialization and they all work.
See
my test server:
public class
TestServer extends ServerResource {
private static volatile
Customer myCustomer = Customer.createSample();
public static void
main(String[] args) throws Exception {
new Server(Protocol.HTTP,
8182, TestServer.class).start();
}
@Get
public Customer retrieve() {
return myCustomer;
}
@Put
public Customer store(Customer customer) {
return myCustomer =
customer;
}
}
The
GWT code looks like this:
[…]
Customer customer = Customer.createSample();
customer.setFirstName(firstName);
customer.setLastName(lastName);
ObjectRepresentation<Customer> or = new
ObjectRepresentation<Customer>(
customer, GreetingService.class);
final Client client = new
Client(Protocol.HTTP);
client.put("http://localhost:8182", or, new
Callback() {
public void
onEvent(Request request, Response response) {
String entity = response.getEntity().getText();
ObjectRepresentation<Customer> or = new
ObjectRepresentation<Customer>(
entity, GreetingService.class);
Customer customer = or.getObject();
[…]
See
the full project attached.
Now,
this is only the first step, I want to make annotated interfaces work on GWT as
well (porting the new ClientResource class) and to remove the constraint of declaring
a special RemoteService interface by providing our own serializer.
I
have started a dedicated specification here:
“GWT
serialization”
http://wiki.restlet.org/developers/282-restlet.html
Feed-back
welcome !
Best
regards,
Jerome Louvel
--
Restlet ~ Founder and Lead developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com