{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1448","repository_url":"https://api.github.com/repos/FasterXML/jackson-databind","labels_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1448/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1448/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1448/events","html_url":"https://github.com/FasterXML/jackson-databind/issues/1448","id":188585844,"number":1448,"title":"UnrecognizedPropertyException occurs non-deterministically","user":{"login":"ckolnik","id":632663,"avatar_url":"https://avatars.githubusercontent.com/u/632663?v=3","gravatar_id":"","url":"https://api.github.com/users/ckolnik","html_url":"https://github.com/ckolnik","followers_url":"https://api.github.com/users/ckolnik/followers","following_url":"https://api.github.com/users/ckolnik/following{/other_user}","gists_url":"https://api.github.com/users/ckolnik/gists{/gist_id}","starred_url":"https://api.github.com/users/ckolnik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ckolnik/subscriptions","organizations_url":"https://api.github.com/users/ckolnik/orgs","repos_url":"https://api.github.com/users/ckolnik/repos","events_url":"https://api.github.com/users/ckolnik/events{/privacy}","received_events_url":"https://api.github.com/users/ckolnik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-11-10T18:40:58Z","updated_at":"2016-11-11T06:12:51Z","closed_at":null,"body":"Here are the classes we have for deserializing JSON that is received from a REST service.\r\n\r\nThe error we see is:\r\n\r\n> com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field \"key\" (class java.util.Optional), not marked as ignorable (0 known properties: ])\r\nat [Source: [B@7b78631d; line: 1, column: 17] (through reference chain: {our-package-name}.GetResponse[\"item\"]->java.util.Optional[\"key\"])\r\n\r\n```\r\n@Data\r\n@RequiredArgsConstructor\r\npublic class GetResponse {\r\n    @NonNull private final Optional<Item> item;\r\n\r\n    @JsonCreator\r\n    private GetResponse(@JsonProperty(\"item\") Item item) {\r\n        this(Optional.ofNullable(item));\r\n    }\r\n\r\n    /* json getters for optional args */\r\n\r\n    @JsonGetter(\"item\")\r\n    private Item getRawItem() {\r\n        return item.orElse(null);\r\n    }\r\n}\r\n\r\n@Getter\r\n@RequiredArgsConstructor(access = PRIVATE)\r\n@EqualsAndHashCode(exclude = \"value\")\r\npublic class Item {\r\n\r\n    private final String key;\r\n    private final Map<String, Object> value;\r\n\r\n    @Builder\r\n    @JsonCreator\r\n    public static Item of(\r\n            @JsonProperty(\"key\")   String key,\r\n            @JsonProperty(\"value\") Map<String, Object> value\r\n    ) {\r\n        if (StringUtils.isNullOrWhitespace(key)) {\r\n            throw new IllegalInputException(\"Item - key must be non-null and non-empty!\");\r\n        }\r\n\r\n        if (value == null) {\r\n            throw new IllegalInputException(\"Item - value must be non-null!\");\r\n        }\r\n\r\n        if (value.isEmpty()) {\r\n            throw new IllegalInputException(\"Item - value must not be empty! If you want to delete, \" +\r\n                                            \"don't put an empty value, call the Delete API.\");\r\n        }\r\n\r\n        return new Item(key, value);\r\n    }\r\n}\r\n\r\n//ObjectMapper\r\nfinal ObjectMapper mapper = new ObjectMapper().configure(MapperFeature.USE_ANNOTATIONS, true);\r\n\r\n//Deserialization\r\nfinal GetResponse result = (GetResponse) this.mapper.readValue(postData, GetResponse.class);\r\n```\r\n\r\nSample JSON that causes the issue but doesn't cause the issue when we created a unit test no matter what we do.\r\n\r\nString format:\r\n\r\n`\"{\\\"item\\\":{\\\"key\\\":\\\"1/1/foo/man,shoo/bar\\\",\\\"value\\\":{\\\"category\\\":\\\"Blurb\\\",\\\"something\\\":\\\"hello\\\",\\\"mid\\\":1,\\\"priority\\\":23,\\\"payload\\\":\\\"helloworld/blahblahblah+XL+interestingdata/moreinterestingdata+V+value\\\",\\\"sid\\\":123456789,\\\"valueType\\\":\\\"mytype\\\",\\\"someId\\\":\\\"1234567890/1/ABCDEFGH/U123456,UPOLHYU/2016-0927T00:00Z\\\",\\\"ANOTHER_VALUE\\\":\\\"OIUPYT,QWERTY\\\",\\\"aType\\\":\\\"sometype\\\",\\\"additionalIdentifiers\\\":[\\\"GHYTUIOD\\\",\\\"GBNYERT,MNJGKHI\\\"],\\\"val\\\":\\\"GJEURIOSPF\\\",\\\"effectiveDate\\\":1474934400000}}}\"`\r\n\r\nJSON:\r\n\r\n`{\r\n  \"item\": {\r\n    \"key\": \"1/1/foo/man,shoo/bar\",\r\n    \"value\": {\r\n      \"category\": \"Blurb\",\r\n      \"something\": \"hello\",\r\n      \"mid\": 1,\r\n      \"priority\": 23,\r\n      \"payload\": \"helloworld/blahblahblah+XL+interestingdata/moreinterestingdata+V+value\",\r\n      \"sid\": 123456789,\r\n      \"valueType\": \"mytype\",\r\n      \"someId\": \"1234567890/1/ABCDEFGH/U123456,UPOLHYU/2016-0927T00:00Z\",\r\n      \"ANOTHER_VALUE\": \"OIUPYT,QWERTY\",\r\n      \"aType\": \"sometype\",\r\n      \"additionalIdentifiers\": [\r\n        \"GHYTUIOD\",\r\n        \"GBNYERT,MNJGKHI\"\r\n      ],\r\n      \"val\": \"GJEURIOSPF\",\r\n      \"effectiveDate\": 1474934400000\r\n    }\r\n  }\r\n}`\r\n\r\nJackson versions:\r\nJackson-annotations  2.8.x;\r\nJackson-core = 2.8.x;\r\nJackson-databind = 2.8.x;\r\n\r\nThe problem is that this only happens like 1/30 times on application startup and once a host starts up and has the issue it continues to have the issue. If we restart the host the issue appears to go away.\r\n\r\nAre there issues with Lombok constructors and JsonCreator that could be causing this? Are Optionals causing an issue? Any help is appreciated.\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/comments/259888952","html_url":"https://github.com/FasterXML/jackson-databind/issues/1448#issuecomment-259888952","issue_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1448","id":259888952,"user":{"login":"cowtowncoder","id":55065,"avatar_url":"https://avatars.githubusercontent.com/u/55065?v=3","gravatar_id":"","url":"https://api.github.com/users/cowtowncoder","html_url":"https://github.com/cowtowncoder","followers_url":"https://api.github.com/users/cowtowncoder/followers","following_url":"https://api.github.com/users/cowtowncoder/following{/other_user}","gists_url":"https://api.github.com/users/cowtowncoder/gists{/gist_id}","starred_url":"https://api.github.com/users/cowtowncoder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cowtowncoder/subscriptions","organizations_url":"https://api.github.com/users/cowtowncoder/orgs","repos_url":"https://api.github.com/users/cowtowncoder/repos","events_url":"https://api.github.com/users/cowtowncoder/events{/privacy}","received_events_url":"https://api.github.com/users/cowtowncoder/received_events","type":"User","site_admin":false},"created_at":"2016-11-11T06:12:50Z","updated_at":"2016-11-11T06:12:50Z","body":"@ckolnik it has to be for classes that trigger the problem; each deserializer is cached separately. However, it should not be necessary for \"child\" types; that is, anything that is directly referenced by, say, `GetResponse` class, should have deserializer fetched as well. So I would start by root type, and that should suffice. As to mock json, simple `{ }` may suffice, and you can (temporarily) enable `ignore all unknown properties` if you do not normally enable it.\r\n"}}
{"actor":{"display_login":"cowtowncoder"}}