{"action":"created","issue":{"url":"https://api.github.com/repos/stleary/JSON-java/issues/275","repository_url":"https://api.github.com/repos/stleary/JSON-java","labels_url":"https://api.github.com/repos/stleary/JSON-java/issues/275/labels{/name}","comments_url":"https://api.github.com/repos/stleary/JSON-java/issues/275/comments","events_url":"https://api.github.com/repos/stleary/JSON-java/issues/275/events","html_url":"https://github.com/stleary/JSON-java/issues/275","id":171713884,"number":275,"title":"Inconsistencies in how null is handled from implementations of JSONString","user":{"login":"johnjaylward","id":383703,"avatar_url":"https://avatars.githubusercontent.com/u/383703?v=3","gravatar_id":"","url":"https://api.github.com/users/johnjaylward","html_url":"https://github.com/johnjaylward","followers_url":"https://api.github.com/users/johnjaylward/followers","following_url":"https://api.github.com/users/johnjaylward/following{/other_user}","gists_url":"https://api.github.com/users/johnjaylward/gists{/gist_id}","starred_url":"https://api.github.com/users/johnjaylward/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnjaylward/subscriptions","organizations_url":"https://api.github.com/users/johnjaylward/orgs","repos_url":"https://api.github.com/users/johnjaylward/repos","events_url":"https://api.github.com/users/johnjaylward/events{/privacy}","received_events_url":"https://api.github.com/users/johnjaylward/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-08-17T17:24:38Z","updated_at":"2016-08-19T20:02:05Z","closed_at":null,"body":"This is related to #273, but could be fixed separate from it if needed. It was first discovered by @run2000 while working on PR #241. \r\n\r\nCurrently output from the library is generated using 2 different methods `JSONObject.valueToString` (used mostly when inserting new objects to a JSONObject or JSONArray) and `JSONObject.writeValue` (used by `toString` and other write operations). Each of these methods have their own implementation for how values are processed and for most things the implementation matches. However, for `JSONString` implementations, we see two different approaches used for null checks from the `JSONString.toJSONString`.\r\n\r\nIn `valueToString` there is an `instanceof String` check that occurs and if it fails, a `JSONException` is thrown.\r\n\r\nIn `writeValue` if `value.toJSONString()` returns `null`, then the quoted value of `value.toString()` is used instead. No exception is thrown.\r\n\r\nThe Java Documentation on [JSONString](https://github.com/stleary/JSON-java/blob/master/JSONString.java) does not explicitly dictate how null values returned from implementations should be handled, but it does seem to imply that the `value.toString()` is correct and not the Exception.\r\n\r\nThis issue is to discuss what type of handling should be used to make this API call consistent as well as to note any possible change to the documentation."},"comment":{"url":"https://api.github.com/repos/stleary/JSON-java/issues/comments/241120397","html_url":"https://github.com/stleary/JSON-java/issues/275#issuecomment-241120397","issue_url":"https://api.github.com/repos/stleary/JSON-java/issues/275","id":241120397,"user":{"login":"stleary","id":5107558,"avatar_url":"https://avatars.githubusercontent.com/u/5107558?v=3","gravatar_id":"","url":"https://api.github.com/users/stleary","html_url":"https://github.com/stleary","followers_url":"https://api.github.com/users/stleary/followers","following_url":"https://api.github.com/users/stleary/following{/other_user}","gists_url":"https://api.github.com/users/stleary/gists{/gist_id}","starred_url":"https://api.github.com/users/stleary/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stleary/subscriptions","organizations_url":"https://api.github.com/users/stleary/orgs","repos_url":"https://api.github.com/users/stleary/repos","events_url":"https://api.github.com/users/stleary/events{/privacy}","received_events_url":"https://api.github.com/users/stleary/received_events","type":"User","site_admin":false},"created_at":"2016-08-19T20:02:05Z","updated_at":"2016-08-19T20:02:05Z","body":"My thinking is that this does not rise to the level of a problem that should be fixed by changing existing behavior. \r\n\r\n- JSONObject.valueToString() is a static method, so any user can call it with any value, and the expectation that it will either return strictly conforming JSON text, or throw an exception. If the object implements JSONString, but fails to return a valid string from toJSONString(), then it seems reasonable in this case to throw an exception. The Javadoc is a little unclear, \"throws JSONException If the value is or contains an invalid number.\"\r\n- It may be called from JSONWriter.value(Object). Although this method is public, it is not commented as if it is intended to be used externally.  Internally, JSONWriter.value() is only called by JSONWriter.value(double), which is also public, but which will never pass along a JSONString. The Javadoc mentions throwing a JSONException on invalid number, which is correct. \r\n- It may be called from JSONArray.join(), also public. The Javadoc only mentions invalid numbers, which seems incomplete. \r\n\r\nI would prefer to fix this by correcting the Javadoc.  But - please let me know if I missed something in the analysis."}}
{"actor":{"display_login":"stleary"}}