Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Real time messaging: types and serialization

    Hi,

    I am experimenting with the real time messaging system.

    I can transfer strings nicely, but I would like to send over objects.

    What kind of serialization / deserialization is in place here? What kind of data can I send through, and how can I restore them on the client side?

    (According to my tests, anything I send is converted to a JavaScriptObject, and with JSOHelper.convertToJava(), I can covert them to LinkedHashMap - but not to the original java class type.)

    Thank you for explaining this.

    Csillag

    #2
    Hi Csillag,
    You can't send true Java objects to the client - instead data sent to the client is serialized into JSON (since of course all GWT ultimately runs as JavaScript in the browser).

    The docs for RPCRequest.setData() (and, on the server side JSTranslater) discuss how standard translations work.

    Therefore you will typically have to convert from the JavaScriptObject into the Java data type you ultimately want to use. convertToJava will give you a LinkedHashMap as noted, and most SmartGWT data objects will optionally take a JavaScript object constructor.
    If you want to work with some other Data object class you'll have to perform the conversion yourself.

    Hope this helps

    Isomorphic Software

    Comment


      #3
      Ultimately, I will need to update some DataSources based on the data.

      I need to handle the following cases:

      - Some records have changed
      - Some records have been inserted
      - Some records have been deleted
      - Invalidate all cache

      So, I can either

      a) send over only the bare minimum info about what happened (like this: datasource X's record #3 have changed), and then run a fetch operation on the DataSource from the client side, or

      b) send over the changed Records, and then on the client side, construct a fake DSResponse object, and pass it to DataSource.updateCaches()

      c) construct a fake (client side) DSResponse on the server side, and send it over to the client, and on the client side, feed it to DataSource.updateCaches().

      Which one is the recommended approach?

      Thank you for your help:

      Csillag

      Comment


        #4
        Probably makes the most sense to do "b".
        The RealtimeMessaging sample in the showcase basically demonstrates this approach:
        http://www.smartclient.com/smartgwte...g_stock_quotes

        Comment

        Working...
        X