{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1410","repository_url":"https://api.github.com/repos/FasterXML/jackson-databind","labels_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1410/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1410/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1410/events","html_url":"https://github.com/FasterXML/jackson-databind/issues/1410","id":182382783,"number":1410,"title":"Duplicate fields result in UnrecognizedPropertyException","user":{"login":"khogeland","id":1495099,"avatar_url":"https://avatars.githubusercontent.com/u/1495099?v=3","gravatar_id":"","url":"https://api.github.com/users/khogeland","html_url":"https://github.com/khogeland","followers_url":"https://api.github.com/users/khogeland/followers","following_url":"https://api.github.com/users/khogeland/following{/other_user}","gists_url":"https://api.github.com/users/khogeland/gists{/gist_id}","starred_url":"https://api.github.com/users/khogeland/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/khogeland/subscriptions","organizations_url":"https://api.github.com/users/khogeland/orgs","repos_url":"https://api.github.com/users/khogeland/repos","events_url":"https://api.github.com/users/khogeland/events{/privacy}","received_events_url":"https://api.github.com/users/khogeland/received_events","type":"User","site_admin":false},"labels":[{"id":362288980,"url":"https://api.github.com/repos/FasterXML/jackson-databind/labels/2.9","name":"2.9","color":"0e8a16","default":false},{"id":484593043,"url":"https://api.github.com/repos/FasterXML/jackson-databind/labels/ACTIVE","name":"ACTIVE","color":"0052cc","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-11T21:46:07Z","updated_at":"2016-11-22T22:42:19Z","closed_at":null,"body":"(version 2.7.8)\n\nThe following code accidentally includes a duplicate \"source\" field as a result of `PROPERTY` instead of `EXISTING_PROPERTY` in the `@JsonTypeInfo` annotation. Deserialization results in a misleading `UnrecognizedPropertyException`.\n\nEnvironmentEvent:\n\n``` java\n@JsonTypeInfo(use=JsonTypeInfo.Id.NAME, include=JsonTypeInfo.As.PROPERTY, property=\"source\")\n@JsonSubTypes({\n        @JsonSubTypes.Type(value = ApiEvent.class, name = \"API\"),\n        @JsonSubTypes.Type(value = BackendEvent.class, name = \"BACKEND\")\n})\npublic abstract class EnvironmentEvent {\n    private String environmentName;\n    private LocalDateTime timeUtc;\n    private String message;\n\n    protected EnvironmentEvent() { } // for deserializer\n    protected EnvironmentEvent(String env, LocalDateTime time, String msg) {\n        environmentName = env;\n        timeUtc = time;\n        message = msg;\n    }\n\n    @Nonnull\n    public String getEnvironmentName() { return environmentName; }\n\n    @Nonnull\n    public LocalDateTime getTimeUtc() { return timeUtc; }\n\n    public abstract EnvironmentEventSource getSource();\n\n    @Nonnull\n    public String getMessage() { return message; }\n}\n```\n\nBackendEvent:\n\n``` java\npublic class BackendEvent extends EnvironmentEvent {\n    private String status;\n\n    private Object resultData;\n\n    protected BackendEvent() {} // for deserializer\n\n    public BackendEvent(String envName, LocalDateTime timeUtc, String message, String status, Object results)\n    {\n        super(envName, timeUtc, message);\n        this.status = status;\n        resultData = results;\n    }\n\n    public static BackendEvent create(String environmentName, String message, String status, Object results) {\n        return new BackendEvent(environmentName,\n                LocalDateTime.now(Clock.systemUTC()), message,\n                status, results);\n    }\n\n    @Nonnull\n    @Override\n    public EnvironmentEventSource getSource() {\n        return EnvironmentEventSource.BACKEND;\n    }\n\n    public String getStatus() {\n        return status;\n    }\n\n    public Object getResultData() {\n        return resultData;\n    }\n\n    @Override\n    public String toString() {\n        return String.format(\"(%s): %s\", status, getMessage());\n    }\n}\n```\n\nTest case:\n\n``` java\nObjectMapper mapper = ObjectMapperFactory.buildObjectMapper();\nEnvironmentEvent event = new BackendEvent(\"foo\", LocalDateTime.now(), \"hello\", \"bar\", null);\nString ser = mapper.writeValueAsString(event);\nmapper.readValue(ser, EnvironmentEvent.class);\n```\n\n```\ncom.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field \"source\" (class xxxxx.event.BackendEvent), not marked as ignorable (5 known properties: \"status\", \"environmentName\", \"timeUtc\", \"message\", \"resultData\"])\n    at com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:62)\n    at com.fasterxml.jackson.databind.DeserializationContext.reportUnknownProperty(DeserializationContext.java:851)\n    at com.fasterxml.jackson.databind.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:1085)\n...\n```\n"},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/comments/262388040","html_url":"https://github.com/FasterXML/jackson-databind/issues/1410#issuecomment-262388040","issue_url":"https://api.github.com/repos/FasterXML/jackson-databind/issues/1410","id":262388040,"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-22T22:42:19Z","updated_at":"2016-11-22T22:42:19Z","body":"Yes, I can reproduce this. The thing that might work here would be to indicate that property `source` is ignorable property, at deserializer level, since polymorphic handler will be separate and work before content serialization, and before deserialization, so it wouldn't be affected.\r\nI'll have to see how `EXISTING_PROPERTY` manages to handle this; perhaps it simply omits type-id handler on serialization.\r\n\r\n"}}
{"actor":{"display_login":"cowtowncoder"}}