I suspect I have run into a serious but hopefully simple to fix issue…
It appears that when a DataSource uses DSDataFormat.JSON then the JSON output produced by SmartClient code is invalid. What seems to be invalid is missing double quotes around the keys/fieldNames within JSON string.
Here is an example of a valid JSON string representing PostalAddress data that is fetched by my DataSource that uses DSDataFormat.JSON.
[
{
"country":"USA",
"city":"Reading"
}
]
However, when I do ValuesManager.saveData() the JSON String that is sent to my DataSource is invalid as it is missing double quotes around field names:
[
{
country:"USA",
city:"Reading"
}
]
Is this something I could be doing wrong? If not, IMHO this is a serious issue. Please let me know if it is an issue and I will file an issue to track it (BTW where to file issues with SmartClient code?). If it is an issue, please suggest any workarounds and rough guess on when the issue could be fixed in svn.
Thanks for your response and guidance on this showstopper issue for me.
AFAIK, This is valid JSON format. In Javascript, {} is the notation for an object and a hash (dictionary, associative array, or whatever you want to call it), and the key/attribute can be in either quotes or not.
Yes, that’s valid JavaScript but not valid JSON. However what you’re seeing is a fallback behavior, not a bug in documented behavior.
dataProtocol, not dataFormat, is what dictates how data is sent to the server. When you have dataProtocol of getParams or postParams and you provide a value that isn’t atomic (eg it’s a nested structure), a fallback strategy of serializing as JavaScript kicks in. We do plan to switch this fallback strategy so that it emits valid JSON, but, the right approach for now is to use one of the JSON libraries for GWT in order to form your own JSON string, then send that as a single param if using dataProtocol of getParams or postParams.
It appears that this issue was fixed yesterday and I am no longer seeing invalid JSON using the maven based nightly SNAPSHOT. Thanks Isomorphic for your help.