{"action":"created","issue":{"url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/79","repository_url":"https://api.github.com/repos/Kotlin/kotlinx.serialization","labels_url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/79/labels{/name}","comments_url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/79/comments","events_url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/79/events","html_url":"https://github.com/Kotlin/kotlinx.serialization/issues/79","id":293842968,"number":79,"title":"Mapper: ignoring @Optional in unmap","user":{"login":"daberni","id":1531969,"avatar_url":"https://avatars3.githubusercontent.com/u/1531969?v=4","gravatar_id":"","url":"https://api.github.com/users/daberni","html_url":"https://github.com/daberni","followers_url":"https://api.github.com/users/daberni/followers","following_url":"https://api.github.com/users/daberni/following{/other_user}","gists_url":"https://api.github.com/users/daberni/gists{/gist_id}","starred_url":"https://api.github.com/users/daberni/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/daberni/subscriptions","organizations_url":"https://api.github.com/users/daberni/orgs","repos_url":"https://api.github.com/users/daberni/repos","events_url":"https://api.github.com/users/daberni/events{/privacy}","received_events_url":"https://api.github.com/users/daberni/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-02T10:33:58Z","updated_at":"2018-04-21T14:54:28Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Given the following class:\r\n\r\n```kotlin\r\n@Serializable\r\ndata class SomeDataClass(\r\n        val x: String? = \"Test\",\r\n\r\n        @Optional\r\n        val y: String? = \"Class\"\r\n)\r\n```\r\n\r\nhaving default values and the `@Optional` attribute. Mapper is ignoring the `@Optional` and throwing an exception in `unmap` when key is missing in map.\r\n\r\n```kotlin\r\n@Test\r\nfun unmapOptionalTest() {\r\n    val map = mapOf(\r\n            \"x\" to \"some other stuff\"\r\n    )\r\n\r\n    val data = Mapper.unmap<SomeDataClass>(map)\r\n\r\n    Assert.assertEquals(\"some other stuff\", data.x)\r\n    Assert.assertEquals(\"Class\", data.y)\r\n}\r\n```\r\n\r\n```\r\njava.util.NoSuchElementException: Key y is missing in the map.\r\n\r\n\tat kotlin.collections.MapsKt__MapWithDefaultKt.getOrImplicitDefaultNullable(MapWithDefault.kt:19)\r\n\tat kotlin.collections.MapsKt__MapsKt.getValue(Maps.kt:270)\r\n\tat kotlinx.serialization.Mapper$InMapper.readTaggedValue(Tagged.kt:353)\r\n\tat kotlinx.serialization.Mapper$InMapper.readTaggedValue(Tagged.kt:352)\r\n\tat kotlinx.serialization.TaggedInput.readTaggedString(Tagged.kt:220)\r\n\tat kotlinx.serialization.TaggedInput.readStringValue(Tagged.kt:240)\r\n\tat kotlinx.serialization.internal.StringSerializer.load(BuiltinSerializers.kt:98)\r\n\tat kotlinx.serialization.internal.StringSerializer.load(BuiltinSerializers.kt:94)\r\n\tat kotlinx.serialization.KInput.readSerializableValue(Serialization.kt:243)\r\n\tat kotlinx.serialization.KInput.readNullableSerializableValue(Serialization.kt:246)\r\n\tat kotlinx.serialization.TaggedInput$readNullableSerializableElementValue$1.invoke(Tagged.kt:265)\r\n\tat kotlinx.serialization.TaggedInput.tagBlock(Tagged.kt:278)\r\n\tat kotlinx.serialization.TaggedInput.readNullableSerializableElementValue(Tagged.kt:265)\r\n\tat SomeDataClass$$serializer.load(SampleTest.kt)\r\n\tat SomeDataClass$$serializer.load(SampleTest.kt:10)\r\n\tat kotlinx.serialization.KInput.read(Serialization.kt:209)\r\n```\r\n\r\nBut the same is working with `JSON`:\r\n\r\n```kotlin\r\n@Test\r\nfun jsonParseTest() {\r\n    val json = \"\"\"\r\n        {\r\n            \"x\": \"some other stuff\"\r\n        }\r\n    \"\"\"\r\n\r\n    val data = JSON.parse<SomeDataClass>(json)\r\n\r\n    Assert.assertEquals(\"some other stuff\", data.x)\r\n    Assert.assertEquals(\"Class\", data.y)\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/comments/383302980","html_url":"https://github.com/Kotlin/kotlinx.serialization/issues/79#issuecomment-383302980","issue_url":"https://api.github.com/repos/Kotlin/kotlinx.serialization/issues/79","id":383302980,"user":{"login":"DALDEI","id":286113,"avatar_url":"https://avatars0.githubusercontent.com/u/286113?v=4","gravatar_id":"","url":"https://api.github.com/users/DALDEI","html_url":"https://github.com/DALDEI","followers_url":"https://api.github.com/users/DALDEI/followers","following_url":"https://api.github.com/users/DALDEI/following{/other_user}","gists_url":"https://api.github.com/users/DALDEI/gists{/gist_id}","starred_url":"https://api.github.com/users/DALDEI/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DALDEI/subscriptions","organizations_url":"https://api.github.com/users/DALDEI/orgs","repos_url":"https://api.github.com/users/DALDEI/repos","events_url":"https://api.github.com/users/DALDEI/events{/privacy}","received_events_url":"https://api.github.com/users/DALDEI/received_events","type":"User","site_admin":false},"created_at":"2018-04-21T14:54:28Z","updated_at":"2018-04-21T14:54:28Z","author_association":"NONE","body":"Just ran into the same problem.  I was hopping to use Mapper as a way of initializing a data class with a map of only the required fields.  This functionality is currently supported by Jackson (was hoping to replace)."}}
{"actor":{"display_login":"DALDEI"}}