{"action":"created","issue":{"url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/124","repository_url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin","labels_url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/124/labels{/name}","comments_url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/124/comments","events_url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/124/events","html_url":"https://github.com/FasterXML/jackson-module-kotlin/issues/124","id":291594960,"number":124,"title":"2.9.4 doesn’t handle `@JsonIgnore`d field with the same name as `@JsonProperty(name)` of other field","user":{"login":"silmeth","id":5329644,"avatar_url":"https://avatars3.githubusercontent.com/u/5329644?v=4","gravatar_id":"","url":"https://api.github.com/users/silmeth","html_url":"https://github.com/silmeth","followers_url":"https://api.github.com/users/silmeth/followers","following_url":"https://api.github.com/users/silmeth/following{/other_user}","gists_url":"https://api.github.com/users/silmeth/gists{/gist_id}","starred_url":"https://api.github.com/users/silmeth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/silmeth/subscriptions","organizations_url":"https://api.github.com/users/silmeth/orgs","repos_url":"https://api.github.com/users/silmeth/repos","events_url":"https://api.github.com/users/silmeth/events{/privacy}","received_events_url":"https://api.github.com/users/silmeth/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-01-25T14:47:48Z","updated_at":"2018-04-06T21:12:11Z","closed_at":null,"author_association":"NONE","body":"I have a data class that looks something like this:\r\n\r\n```kotlin\r\ndata class DTO(@JsonProperty(\"name\") val name: String,\r\n               @JsonIgnore val query: NonSerializableClass,\r\n               @JsonProperty(\"query\") val rawQuery: String) {\r\n    @JsonCreator\r\n    constructor(@JsonProperty(\"name\") name: String,\r\n                @JsonProperty(\"query\") rawQuery: String) :\r\n        this(name, parseNonSerializableField(rawQuery), rawQuery)\r\n}\r\n```\r\n\r\nWhere `NonSerializableClass` is a complicated external class that I do not want to write custom (de)serializers for, and whose instances can be easily created by parsing the `rawQuery` string.\r\n\r\nWith Jackson 2.9.3 and `jackson-module-kotlin` 2.9.3 string of the kind `{\"name\": \"foo\", \"query\": \"bar\"}` get nicely serialized into `DTO` and the object created can be nicely deserialized.\r\n\r\nBut with Jackson + `jackson-module-kotlin` 2.9.4 I get a `com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException` \"due to missing (therefore NULL) value for creator parameter rawQuery which is a non-nullable type\" (but after a bit of fiddling with it, I found out that the real problem is that there is a `@JsonIgnore val query` – with the same name as a `@JsonProperty(\"name\")` of another field).\r\n\r\nA minimal test for this, that passes with version 2.9.3, but fails with 2.9.4, looks like this:\r\n\r\n```kotlin\r\nimport com.fasterxml.jackson.annotation.JsonCreator\r\nimport com.fasterxml.jackson.annotation.JsonIgnore\r\nimport com.fasterxml.jackson.annotation.JsonProperty\r\nimport com.fasterxml.jackson.databind.ObjectMapper\r\nimport com.fasterxml.jackson.module.kotlin.KotlinModule\r\nimport com.fasterxml.jackson.module.kotlin.readValue\r\nimport org.junit.jupiter.api.Test\r\n\r\ninternal class DeserializationTest {\r\n    @Test\r\n    fun test() {\r\n        val objMapper = ObjectMapper().registerModule(KotlinModule())\r\n\r\n        // with 2.9.3 prints\r\n        //     Foo(name=foo, query=NonSerializable, rawQuery=bar)\r\n        // but with 2.9.4 throws:\r\n        //     com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException: Instantiation of [simple type, class DeserializationTest$Foo] value failed for JSON property query due to missing (therefore NULL) value for creator parameter rawQuery which is a non-nullable type\r\n        //      at [Source: (String)\"{\"name\": \"foo\", \"query\": \"bar\"}\"; line: 1, column: 31] (through reference chain: DeserializationTest$Foo[\"query\"])\r\n        val deserialized: Foo = objMapper.readValue(\"{\\\"name\\\": \\\"foo\\\", \\\"query\\\": \\\"bar\\\"}\")\r\n        println(deserialized)\r\n\r\n        val serialized = objMapper.writeValueAsString(deserialized)\r\n\r\n        // with 2.9.3 prints\r\n        //     {\"name\":\"foo\",\"query\":\"bar\"}\r\n        println(serialized)\r\n    }\r\n\r\n    class NonSerializable(private val field: Any?) {\r\n        override fun toString() = \"NonSerializable\"\r\n    }\r\n\r\n    data class Foo(@JsonProperty(\"name\") val name: String,\r\n                   @JsonIgnore val query: NonSerializable,\r\n                   @JsonProperty(\"query\") val rawQuery: String) {\r\n        @JsonCreator\r\n        constructor(@JsonProperty(\"name\") name: String,\r\n                    @JsonProperty(\"query\") rawQuery: String): this(name, NonSerializable(rawQuery), rawQuery)\r\n    }\r\n}\r\n```\r\n\r\nAfter changing the name of the non-serializable `@JsonIgnore`d field `query` to something else, like `ignoredQuery`, it works in 2.9.4 too.\r\n\r\nBut that still looks like a bug, and I’d like not to change the API of my class (where value `query` returns the non-serializable object) nor to force all places where this data class is serialized to change its JSON schema (to use another field like eg. `rawQuery` instead of `query`)."},"comment":{"url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/comments/379380866","html_url":"https://github.com/FasterXML/jackson-module-kotlin/issues/124#issuecomment-379380866","issue_url":"https://api.github.com/repos/FasterXML/jackson-module-kotlin/issues/124","id":379380866,"user":{"login":"jskierbi","id":743666,"avatar_url":"https://avatars2.githubusercontent.com/u/743666?v=4","gravatar_id":"","url":"https://api.github.com/users/jskierbi","html_url":"https://github.com/jskierbi","followers_url":"https://api.github.com/users/jskierbi/followers","following_url":"https://api.github.com/users/jskierbi/following{/other_user}","gists_url":"https://api.github.com/users/jskierbi/gists{/gist_id}","starred_url":"https://api.github.com/users/jskierbi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jskierbi/subscriptions","organizations_url":"https://api.github.com/users/jskierbi/orgs","repos_url":"https://api.github.com/users/jskierbi/repos","events_url":"https://api.github.com/users/jskierbi/events{/privacy}","received_events_url":"https://api.github.com/users/jskierbi/received_events","type":"User","site_admin":false},"created_at":"2018-04-06T21:12:11Z","updated_at":"2018-04-06T21:12:11Z","author_association":"NONE","body":"I've debugged a bit. \r\n\r\nSeems the test @silmeth provided is broken by this particular commit: https://github.com/FasterXML/jackson-databind/commit/562484cf45e8f0c50fc03d761ae80bfb1754ab3a\r\n\r\nChange in this class: ```PropertyBasedCreator.java```\r\n\r\n```query``` is not added to _propertyLookup although defined in creator: ```@JsonProperty(\"query\") rawQuery: String``` "}}
{"actor":{"display_login":"jskierbi"}}