{"action":"opened","issue":{"url":"https://api.github.com/repos/resty-gwt/resty-gwt/issues/336","repository_url":"https://api.github.com/repos/resty-gwt/resty-gwt","labels_url":"https://api.github.com/repos/resty-gwt/resty-gwt/issues/336/labels{/name}","comments_url":"https://api.github.com/repos/resty-gwt/resty-gwt/issues/336/comments","events_url":"https://api.github.com/repos/resty-gwt/resty-gwt/issues/336/events","html_url":"https://github.com/resty-gwt/resty-gwt/issues/336","id":196097730,"number":336,"title":"Enum serialization/deserialization using ordinal","user":{"login":"chinshaw","id":3654118,"avatar_url":"https://avatars.githubusercontent.com/u/3654118?v=3","gravatar_id":"","url":"https://api.github.com/users/chinshaw","html_url":"https://github.com/chinshaw","followers_url":"https://api.github.com/users/chinshaw/followers","following_url":"https://api.github.com/users/chinshaw/following{/other_user}","gists_url":"https://api.github.com/users/chinshaw/gists{/gist_id}","starred_url":"https://api.github.com/users/chinshaw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chinshaw/subscriptions","organizations_url":"https://api.github.com/users/chinshaw/orgs","repos_url":"https://api.github.com/users/chinshaw/repos","events_url":"https://api.github.com/users/chinshaw/events{/privacy}","received_events_url":"https://api.github.com/users/chinshaw/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-12-16T16:26:18Z","updated_at":"2016-12-16T16:26:18Z","closed_at":null,"body":"I am trying to cut down on the amount of data for a payload and wanted to convert enum strings in a map to ordinals. I ran into a problem when trying to deserialize the object using resty where the check of the key was checking to see if the value was a string. I traced it down to the line  `p(JSON_STRING_CLASS + \" str = value.isString();\");` in JsonEncoderDecoderClassCreator.java. \r\n\r\nThe problem was that I was sending the value for the key as \"0\", \"1\" etc. This check was checking to see if the ordinal value was a string and this was failing. I Then altered the method to add a single char ahead of the ordinal value and the error stopped. I had to handle stripping out this character but it is working.\r\n\r\n\r\nThis is the working implementation where I append the \"I\" character to the ordinal value and then strip it off using the `@JsonCreator` . I can post a fix later. I left a note in the code to come back and revisit it later on.\r\n\r\n```\r\npublic enum Metric implements IMetric {\r\n\t\r\n\tBID_ATTEMPT(ICountsRepository.BID_ATTEMPT_KEY, Long.class), \r\n\tBID_WIN(ICountsRepository.BID_WIN_TOTAL_KEY, Long.class),\r\n\tIMPRESSION(ICountsRepository.IMPRESSION_KEY, Long.class),\r\n\tCOST(ICountsRepository.COST_KEY, Double.class),\r\n\tACTION_CLICK(ICountsRepository.ACTION_CLICK_KEY, Long.class),\r\n\tSECONDARY_ACTIONS(ICountsRepository.SECONDARY_ACTIONS_KEY, Long.class),\r\n\tTHIRDPARTY_ACTIONS(ICountsRepository.THIRD_PARTY_ACTIONS_TRACKING_KEY, Long.class);\r\n\r\n\tprivate final String key;\r\n\r\n\tprivate Class<? extends Number> valueType;\r\n\r\n\tMetric(final String key, Class<? extends Number> valueType) {\r\n\t\tthis.key = key;\r\n\t\tthis.valueType = valueType;\r\n\t}\r\n\r\n\tpublic String getKey() {\r\n\t\treturn key;\r\n\t}\r\n\r\n\tpublic Class<? extends Number> getValueType() {\r\n\t\treturn valueType;\r\n\t}\r\n\t\r\n    @JsonValue\r\n    public String toJson() {\r\n        return \"I\" + Integer.toString(ordinal());\r\n    }\r\n    \r\n    @JsonCreator\r\n    public static Metric fromJson(final String ordinalString) {\r\n        char[] chars = ordinalString.toCharArray();\r\n        return Metric.values()[Integer.parseInt(String.valueOf(chars[1]))];\r\n    }   \r\n}\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"chinshaw"}}