开发者

JSON: java.lang.Double null is converted to zero; How should I handle in client?

开发者 https://www.devze.com 2023-02-19 08:45 出处:网络
I have a client that makes AJAX requests. The Java application server creates a list of objects that have java.lang.Double instance fields. Depending on the request, some of these instance fields may

I have a client that makes AJAX requests. The Java application server creates a list of objects that have java.lang.Double instance fields. Depending on the request, some of these instance fields may be null on all the objects. But when the list of objects is converted (via JSONArray.fromObject) nulls are converted to zero.

So, on the client side, these show up as zero values to the user. How should I handle this so the user does not see these values? I would think it would be best stop the server from sending zero in the first place (perhaps by not sending the field), but I'm not sure how to do this cleanly with JSON. Less favorably, I could figure out someway on the client to know what was requested in the handler and prevent showing data unles开发者_如何学JAVAs the client requested. In that case, is there a way to get the HTTP request param data from the XMLHttpRequest object?

Many thanks in advance for your help.


Use a different JSON parser (Crockford's is one possibility). That nulls as 0 stuff seems like a bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消