Hi,

I had data object that contains attributes as string. I had no trouble in converting it to a map of <String,String> and push it(where key was the attributeName, and value was attributeValue). But now, the data model is going a change, along with the previous attributes now it has a List<Object> where Object it self contains attributes as String. How should I handle this? Is it possible or advisable to have the data model that needs to be pushed in this structure? Please advise.

A sample scenario is presented below. Class Complex contains List of Phones.
Class Complex{
String name;
String id;
List<Phone> simples;
}
Class Phone{
String phone;
}
Thanks,
Shreyas
Hi Shreyas,

If you want to take benefit of the highly efficient delivery mechanisms of Lightstreamer (such as delta delivery and message conflation), you should map any data model you have to a table-based data model. So, in this case, it is up to you to find the right mapping.

On the other hand, if you don't need optimized delivery, you can use opaque data types. In other words, you can serialize your complex data object into a string (through JSON, XML, or any other technique) and push it as a single field. Your client-side code will do the opposite operation, deserializing the string and getting a full-blown object again.

Again, consider that by using opaque data types, you actually hide the data model to Lightstreamer, which cannot parse the messages to extract the deltas. So, each message will be delivered "as is" to the client (thus consuming more bandwidth, also due to the overhead of the serialization syntax).

Regards,
Alessandro
Hi Alessandro,

Thanks for the reply. I get the point.

Regards,
Shreyas
18 days later
Hello,

I'm attempting to use JSON and a NonVisualTable on the client side - but I seem to be having trouble with including the json.js file (e.g. using http://www.json.org/json.js) with the lightstreamer js files.

The updates are working as expected when I don't include the json.js file, but the item updates don't seem to be getting picked up when the json.js is included into the page.

This is the set up I have:
<html>

<head>
	<title></title>
	<script src="js/json.js" type="text/javascript"></script>
	<script src="ls/lscommons.js" type="text/javascript"></script>
	<script src="ls/lspushpage.js" type="text/javascript"></script>
</head>

<body>
<div source="lightstreamer" table="test" item="item-test" field="fieldA" id="fieldA">
loading...
</div>

<script>

	var page = new PushPage();
	page.onEngineCreation = function(engine) {
		engine.connection.setAdapterName("TEST_ADAPTER");
		engine.changeStatus("STREAMING");
	}
	page.bind();
	page.createEngine("TestApp", "LS", "SHARE_SESSION");

	var group = ["item-test"];
	var schema = ["fieldA"];
	var pushtable = new NonVisualTable(group, schema, "MERGE");
	pushtable.setSnapshotRequired(true);

	// callback that receives the updates from the Server
	pushtable.onItemUpdate = function (item, updateInfo) {
		//alert("update received");
		if (item == null) {
			//alert("item is empty");
                        return;
		}
		if (updateInfo == null) {
			//alert("updateInfo is empty");
			return;
		}
		var value = updateInfo.getNewValue("fieldA");
		var fieldADiv = document.getElementById("fieldA");
		fieldADiv.innerHTML = value;
               
               //todo: retrieve properties from the JSON obejct
	};

	//add the table to the page
	page.addTable(pushtable, "test");

</script>

</body>
</html>
Is there something else I need to include to allow JSON to be used?

Many Thanks,

C
the problem with the json.js file is that such library extends the Object's prototype that in turn breaks our code.

If you use the updated version of the json library (http://www.JSON.org/json2.js ) no conflicts will occur.

hope that helps.