{"action":"created","issue":{"url":"https://api.github.com/repos/google/gson/issues/1203","repository_url":"https://api.github.com/repos/google/gson","labels_url":"https://api.github.com/repos/google/gson/issues/1203/labels{/name}","comments_url":"https://api.github.com/repos/google/gson/issues/1203/comments","events_url":"https://api.github.com/repos/google/gson/issues/1203/events","html_url":"https://github.com/google/gson/issues/1203","id":281157986,"number":1203,"title":"Invalid JSON from Double.NaN as JsonObject property","user":{"login":"danorton2","id":11525236,"avatar_url":"https://avatars2.githubusercontent.com/u/11525236?v=4","gravatar_id":"","url":"https://api.github.com/users/danorton2","html_url":"https://github.com/danorton2","followers_url":"https://api.github.com/users/danorton2/followers","following_url":"https://api.github.com/users/danorton2/following{/other_user}","gists_url":"https://api.github.com/users/danorton2/gists{/gist_id}","starred_url":"https://api.github.com/users/danorton2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danorton2/subscriptions","organizations_url":"https://api.github.com/users/danorton2/orgs","repos_url":"https://api.github.com/users/danorton2/repos","events_url":"https://api.github.com/users/danorton2/events{/privacy}","received_events_url":"https://api.github.com/users/danorton2/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-12-11T20:34:20Z","updated_at":"2017-12-11T23:09:00Z","closed_at":null,"author_association":"NONE","body":"Double.NaN as JsonObject property generates invalid JSON and does not throw exception\r\nThis is with 2.8.2\r\nCode fragment:\r\n```java\r\n    final Gson gson = new GsonBuilder().serializeNulls().create();\r\n    JsonObject jsonObject = new JsonObject();\r\n    jsonObject.addProperty(\"invalidDouble\", Double.NaN);\r\n    JsonElement jsonElement = jsonObject;\r\n    log(\"As property within object: \" + jsonElement.toString()); // expect this to throw exception\r\n    jsonElement = new JsonPrimitive(Double.NaN);\r\n    log(\"As primitive: \" + jsonElement.toString());  // expect this to throw exception\r\n    jsonElement = gson.toJsonTree(Double.NaN);\r\n    log(\"As raw value toJsonTree: \" + jsonElement.toString());  // this throws exception, as expected\r\n```\r\nOutput:\r\n```\r\nAs property within object: {\"invalidDouble\":NaN}\r\nAs primitive: NaN\r\nException in thread \"main\" java.lang.IllegalArgumentException: NaN is not a valid double value as per JSON specification. To override this behavior, use GsonBuilder.serializeSpecialFloatingPointValues() method.\r\n\tat com.google.gson.Gson.checkValidFloatingPoint(Gson.java:324)\r\n\tat com.google.gson.Gson$1.write(Gson.java:292)\r\n\tat com.google.gson.Gson$1.write(Gson.java:278)\r\n\tat com.google.gson.Gson.toJson(Gson.java:669)\r\n\tat com.google.gson.Gson.toJsonTree(Gson.java:562)\r\n\tat com.google.gson.Gson.toJsonTree(Gson.java:541)\r\n```"},"comment":{"url":"https://api.github.com/repos/google/gson/issues/comments/350888844","html_url":"https://github.com/google/gson/issues/1203#issuecomment-350888844","issue_url":"https://api.github.com/repos/google/gson/issues/1203","id":350888844,"user":{"login":"danorton2","id":11525236,"avatar_url":"https://avatars2.githubusercontent.com/u/11525236?v=4","gravatar_id":"","url":"https://api.github.com/users/danorton2","html_url":"https://github.com/danorton2","followers_url":"https://api.github.com/users/danorton2/followers","following_url":"https://api.github.com/users/danorton2/following{/other_user}","gists_url":"https://api.github.com/users/danorton2/gists{/gist_id}","starred_url":"https://api.github.com/users/danorton2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danorton2/subscriptions","organizations_url":"https://api.github.com/users/danorton2/orgs","repos_url":"https://api.github.com/users/danorton2/repos","events_url":"https://api.github.com/users/danorton2/events{/privacy}","received_events_url":"https://api.github.com/users/danorton2/received_events","type":"User","site_admin":false},"created_at":"2017-12-11T23:09:00Z","updated_at":"2017-12-11T23:09:00Z","author_association":"NONE","body":"See also:\r\n- #372 - GsonBuilder.setLenient(false)"}}
{"actor":{"display_login":"danorton2"}}