Announcement

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

    JSON Fetch / Null result == no callback

    Hi,

    With Isomorphic SmartClient 8 GA (JS), I use the following code:

    Code:
    var ds = DataSource.create
    ({
    	dataFormat : 'json',
    	dataProtocol : 'postMessage',
    	recordXPath : '/Allowance',
    	dataURL : encodeURI(myURL),
    	fields :
    	[
    		{ name : 'Buyer.Code', type : 'text' },
    		{ name : 'Buyer.Name', type : 'text' }
    	]
    });
    
    var requestProperties =
    {
    	httpMethod : 'POST',
    	contentType : 'application/json',
    	httpHeaders : { 'Accept' : 'application/json' },
    	data : myJSONdata,
    	useSimpleHttp : true,
    	bypassCache : true,
    	showPrompt : true
    };
    
    ds.fetchData(null,
    	function(dsResponse, data, dsRequest)
    	{
               // I need this callback to get executed even when data == null
    	}, requestProperties);
    When my JSON service returns no data, I get the following warning in the ISC console :

    Code:
    08:47:09.471:XRP8:WARN:DataSource:isc_DataSource_1:Evaluating JSON reply resulted in empty value. JSON text:
    "null"
    And my callback never gets executed.

    I quickly looked at the DataSource code and found the following in the _handleJSONTextReply method:

    Code:
           // warn and bail if server response object evals to null.
           // This can happen if the response is "", or if it's something like "var foo = {};"
           // where the result of the eval is undef.
           // Avoids a JS error in handleJSONReply
           if (jsonObjects == null) {
               this.logWarn("Evaluating JSON reply resulted in empty value. JSON text:\r" 
                            + this.echo(jsonText));
             return;
         }
    Is there any way to have the callback executed with data == null as its parameter ?

    Thanks again for the assistance,

    #2
    You do need to send a valid JSON response - it can be just {}, is that an issue?

    Comment


      #3
      I use the Jersey/JAXB framework on the server, and somehow when it serialized empty collections, it returns null, instead of [] ...

      I'm currently investigating if I can change that behavior on the server without breaking anything else, and I'll let you know if I come up
      with something.

      If I can't, would it be possible for you guys not to break to function call flow, and have my fetch() callback fired with null ? or some
      other alternative ?

      In any case, I'll come back to you with more info if I can fix this on the server ...

      Comment


        #4
        I've been playing with Jersey/JAXB for a while trying to have it return empty collections as [], but can't make it happen.

        How complex/feasible would it be for you guys to have the callback fired with a null when this happens? Or do you have
        something else you could propose?

        Thanks,

        Comment


          #5
          We plan to take a look at it, but unless you fix the serialization behavior you'd still have a warning every time. Better to catch the bad cases in JAXB by looking at the data right before passing to JAXB and doing a direct Servlet response in that case.

          Comment


            #6
            We fixed this in our JAXB collection implementation (server) so this is
            no longer an issue for us as the returned data is now JSON compliant.

            Thanks,

            Comment

            Working...
            X