Monday, October 10th, 2005

Java object serialization for Ajax

Category: Articles

IBM developerWorks has a nice Java-based Ajax article: Java object serialization for Ajax:

If you’re doing Java Web development using Asynchronous JavaScript and XML (Ajax), then delivering data from the server to the client is probably your top concern. In this second article in the Ajax for Java developers series, Philip McCarthy walks you through five approaches to Java object serialization and gives you all the information you need to choose the data format and technology best suited to your application.

Philip walks through producing XML (manually and via binding frameworks), using page templating, not using XML, and then JSON:

public JSONObject toJSONObject() {

  JSONObject json = new JSONObject();
  json.put("id",id);
  json.put("cost",getFormattedCost());
  json.put("date",date);

  JSONArray jsonItems = new JSONArray();
  for (Iterator iter = 
   items.iterator() ; iter.hasNext() ; ) {
    jsonItems.put(iter.next().toJSONObject());
  }
  json.put("items",jsonItems);

  return json;
}

The article finishes with a nice comparison of the various techniques, in Philips opinion:

comparing-serialization-tab.png

Posted by Dion Almaer at 9:36 am
Comment here

+++--
3.3 rating from 6 votes

Comments Here »

Comments feed

Leave a comment

You must be logged in to post a comment.