{"action":"created","issue":{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/178","labels_url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/178/labels{/name}","comments_url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/178/comments","events_url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/178/events","html_url":"https://github.com/chrsmith/google-api-java-client/issues/178","id":59367087,"number":178,"title":"map empty XML attribute to null","user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/labels/auto-migrated","name":"auto-migrated","color":"ededed"},{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/labels/Component-XML","name":"Component-XML","color":"ededed"},{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/labels/Milestone-Version1.5.0","name":"Milestone-Version1.5.0","color":"ededed"},{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/labels/Priority-Medium","name":"Priority-Medium","color":"ededed"},{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/labels/Type-Enhancement","name":"Type-Enhancement","color":"ededed"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-28T23:56:06Z","updated_at":"2015-02-28T23:56:07Z","closed_at":"2015-02-28T23:56:07Z","body":"```\nI have a class that maps an XML attribue to a BigDecimal.\n\npublic class SalesTaxRate\n{\n    @Key(\"@rate\")\n    public BigDecimal totalRate;\n}\n\nI don't have any control over the web service that I'm calling, but I noticed \nthat they sometimes send an empty attribute value for \"rate\" and when \ngoogle-api-java-client tries to map the empty string to a BigDecimal, a \nNumberFormatException is thrown.\n\n<response rate=\"\" />\n\nPartial stacktrace:\n\njava.lang.NumberFormatException\n\tat java.math.BigDecimal.<init>(BigDecimal.java:457)\n\tat java.math.BigDecimal.<init>(BigDecimal.java:647)\n\tat com.google.api.client.util.FieldInfo.parsePrimitiveValue(FieldInfo.java:240)...\n\nIs there a way around this problem without resorting to using String instead of \nBigDecimal?\n\nIf not, I would like to request that empty attribute values be mapped to null, \nas though the attribute wasn't present at all. Perhaps there could be an \nannotation to achieve this, if this could not be a global behavior.\n```\n\nOriginal issue reported on code.google.com by `tra...@circutus.com` on 13 Apr 2011 at 9:12"},"comment":{"url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/comments/76558515","html_url":"https://github.com/chrsmith/google-api-java-client/issues/178#issuecomment-76558515","issue_url":"https://api.github.com/repos/chrsmith/google-api-java-client/issues/178","id":76558515,"user":{"login":"GoogleCodeExporter","id":9614759,"avatar_url":"https://avatars.githubusercontent.com/u/9614759?v=3","gravatar_id":"","url":"https://api.github.com/users/GoogleCodeExporter","html_url":"https://github.com/GoogleCodeExporter","followers_url":"https://api.github.com/users/GoogleCodeExporter/followers","following_url":"https://api.github.com/users/GoogleCodeExporter/following{/other_user}","gists_url":"https://api.github.com/users/GoogleCodeExporter/gists{/gist_id}","starred_url":"https://api.github.com/users/GoogleCodeExporter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GoogleCodeExporter/subscriptions","organizations_url":"https://api.github.com/users/GoogleCodeExporter/orgs","repos_url":"https://api.github.com/users/GoogleCodeExporter/repos","events_url":"https://api.github.com/users/GoogleCodeExporter/events{/privacy}","received_events_url":"https://api.github.com/users/GoogleCodeExporter/received_events","type":"User","site_admin":false},"created_at":"2015-02-28T23:56:07Z","updated_at":"2015-02-28T23:56:07Z","body":"```\nThanks for the response. The key issue here for me is that right now, the way \nit works, deserialization can break for an empty XML attribute. I think that no \nmatter what a long term solution is, a short term solution should be provided \nso that the NumberFormatException is not thrown, and the BigDecimal (or other \nobjects like BigInteger) are deserialized to null.\n\nFor a long term solution, we should probably think in terms of how XML schemas \n(or similar mechanisms) define attributes as either \"required\" or \"optional\". \nThere could be an annotation specifying whether or not an attribute is \n\"required\" explicitly, so that a required attribute that is null will be \nserialized to an empty attribute value. For the case of BigDecimal, you would \nstill need to deserialize to null, even if the XML attribute is empty.\n\nIt wouldn't be easy to determine that the original attribute was empty in the \nfirst place. I guess you could have an annotation that defines a value to set \nthe BigDecimal to when the original attribute is empty (e.g., set to minimum \npossible BigDecimal value). To be honest, I'm not sure it is worth it.\n\nTo answer your last few questions, the web service interprets rate=\"\" as \nmeaning that they can not determine the rate. I think it's just a bad design \ndecision on their part (and probably too late to change for them, because I'm \nsure thousands of applications already use their web service).\n\n```\n\nOriginal comment by `tra...@circutus.com` on 19 Apr 2011 at 3:31"}}