Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean property setter is skipped if name isX prefixed #798

Open
3 tasks done
IceBlizz6 opened this issue May 9, 2024 · 4 comments
Open
3 tasks done

Boolean property setter is skipped if name isX prefixed #798

IceBlizz6 opened this issue May 9, 2024 · 4 comments
Labels

Comments

@IceBlizz6
Copy link

IceBlizz6 commented May 9, 2024

Search before asking

  • I searched in the issues and found nothing similar.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem only occurs when using Kotlin.

Describe the bug

Jackson will not call property setter for boolean properties if the name is prefixed with isX.
Value is still assigned, which makes me suspect that it is assigning value to the backing field directly instead.

To Reproduce

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import com.fasterxml.jackson.module.kotlin.readValue
import org.junit.Assert
import org.junit.Test

class ReadTest {
	class Dummy {
		var isAlive: Boolean? = null
			set(value) {
				field = value
				setterUsed = true
			}

		var setterUsed = false
	}

	@Test
	fun readPrefixedValueTest() {
		val objectMapper = jacksonObjectMapper()
		val dummy = objectMapper.readValue<Dummy>("{ \"isAlive\": true }")
		Assert.assertTrue(dummy.setterUsed)
	}
}

Expected behavior

When running the reproduction case then the test should succeed.
The setter of isAlive property should be called.

Versions

Kotlin: 1.9.23
Jackson-module-kotlin: 2.17.1

Additional context

No response

@IceBlizz6 IceBlizz6 added the bug label May 9, 2024
@k163377
Copy link
Contributor

k163377 commented Jun 15, 2024

Confirmed.
The KotlinModule does not currently assume deserialization using setter, which seems to be a missing feature.

is AnnotatedMethod -> if (member.parameterCount == 0) {
if (useKotlinPropertyNameForGetter) {
// Fall back to default if it is a getter-like function
getterNameFromKotlin(member) ?: getterNameFromJava(member)
} else getterNameFromJava(member)
} else null

Since implementation is undecided, please use a workaround such as JsonProperty.

@IceBlizz6
Copy link
Author

Thank you for your response.

Is there hope for a real solution on this in the future?
(other than the workaround)

@AnneMayor
Copy link

AnneMayor commented Jul 21, 2024

I am also curious if this feature could be released for some day.

@k163377
Copy link
Contributor

k163377 commented Sep 14, 2024

At least I don't have time to work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants