سؤال

I'd like to produce following behaviour:

User in the browser saves some entity. After entity is saved on the server side, it generates notification and it must notify all other clients by means of Atmosphere with updated entity instance.

So the problem is how I can push POJO entity through Atmosphere interface? Last one supports Serializable types to transfer over wire whereas RequestFactory has another serialization mechanism.

So I need transform POJO entity to autobean as this is done by RF and send to client. Anybody knows how it can be done?

هل كانت مفيدة؟

المحلول

You can just use create AutoBeans and use them instead of POJOs in your client code. AutoBeans can be easily serialized to/from JSON in GWT and JSON can be transferred. That's what I do in my web-socket based GWT app.

On the server you can create the same AutoBean factory that you use on the client. Instead of GWT.create we use AutoBeanFactorySource:

MyDataFactory factory = AutoBeanFactorySource.create(MyDataFactory.class)
AutoBean<MyData> myDataAutoBean = factory.myData();
MyData data = myDataAutoBean.as();
data.setValue(1); // call all kinds of setters

// to converto AutoBean to JSON
String json = AutoBeanCodex.encode(myDataAutoBean).getPayload();

On the client side we use the AutoBeanCodex to decode json into an AutoBean

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top