{"action":"created","issue":{"url":"https://api.github.com/repos/square/moshi/issues/114","labels_url":"https://api.github.com/repos/square/moshi/issues/114/labels{/name}","comments_url":"https://api.github.com/repos/square/moshi/issues/114/comments","events_url":"https://api.github.com/repos/square/moshi/issues/114/events","html_url":"https://github.com/square/moshi/issues/114","id":123307450,"number":114,"title":"Allow null-values for primitive types","user":{"login":"ChristianBecker","id":1763815,"avatar_url":"https://avatars.githubusercontent.com/u/1763815?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianBecker","html_url":"https://github.com/ChristianBecker","followers_url":"https://api.github.com/users/ChristianBecker/followers","following_url":"https://api.github.com/users/ChristianBecker/following{/other_user}","gists_url":"https://api.github.com/users/ChristianBecker/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianBecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianBecker/subscriptions","organizations_url":"https://api.github.com/users/ChristianBecker/orgs","repos_url":"https://api.github.com/users/ChristianBecker/repos","events_url":"https://api.github.com/users/ChristianBecker/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianBecker/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-21T16:11:38Z","updated_at":"2016-01-20T15:02:40Z","closed_at":"2016-01-20T15:02:40Z","body":"Gson and Moshi differ in their deserialization of `null` to primitive types:\r\n * Gson allows `null` for a primitive type, like `int`. It will result in `0`.\r\n * Moshi is strict in this way and will throw an exception.\r\n\r\nWhile I understand that the model should be `Integer` in cases where `null` is expected/allowed, this difference in both libraries makes the migration difficult.\r\n\r\nDo you plan to allow `null` for primitive types? Maybe not by default but as an option on `Moshi.Builder`? If not this difference should at least be mentioned in the `README.md`."},"comment":{"url":"https://api.github.com/repos/square/moshi/issues/comments/173229571","html_url":"https://github.com/square/moshi/issues/114#issuecomment-173229571","issue_url":"https://api.github.com/repos/square/moshi/issues/114","id":173229571,"user":{"login":"ChristianBecker","id":1763815,"avatar_url":"https://avatars.githubusercontent.com/u/1763815?v=3","gravatar_id":"","url":"https://api.github.com/users/ChristianBecker","html_url":"https://github.com/ChristianBecker","followers_url":"https://api.github.com/users/ChristianBecker/followers","following_url":"https://api.github.com/users/ChristianBecker/following{/other_user}","gists_url":"https://api.github.com/users/ChristianBecker/gists{/gist_id}","starred_url":"https://api.github.com/users/ChristianBecker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ChristianBecker/subscriptions","organizations_url":"https://api.github.com/users/ChristianBecker/orgs","repos_url":"https://api.github.com/users/ChristianBecker/repos","events_url":"https://api.github.com/users/ChristianBecker/events{/privacy}","received_events_url":"https://api.github.com/users/ChristianBecker/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T15:02:40Z","updated_at":"2016-01-20T15:02:40Z","body":"I kind of mimic the Gson behavior by using the following custom FromJson method:\r\n\r\n```\r\n    @FromJson\r\n    public int intFromJson(@Nullable Integer value) {\r\n        if (value == null) {\r\n            // TODO: Log some kind of message to fix the POJO\r\n            return 0;\r\n        }\r\n\r\n        return value;\r\n    }\r\n```\r\n\r\nWhile I definitely want to get rid of this, this helps me to overcome any edge cases in my POJOs.\r\n\r\nFYI: I had a hard time figuring out that a custom Nullable annotation is actually necessary. The one from the Support-Annotations has `RetentionPolicy.CLASS`, so Moshi can't see it at runtime and makes the adapter not-nullable. This isn't included in the docs, so maybe this would be worth noticing.\r\n\r\nThank you anyway for this great library!"}}