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

@JsonProperty annotation is not working for fields with type of value class. #540

Closed
matek2305 opened this issue Jan 12, 2022 · 3 comments
Closed
Labels

Comments

@matek2305
Copy link

Describe the bug
@JsonProperty annotation is not working for fields with type of value class.

To Reproduce

internal class ValueClassSerializationTest {

    private val mapper = jsonMapper {
        addModule(kotlinModule())
    }

    @Test
    internal fun `@JsonProperty value is used for value class typed fields`() {
        val container = Container(
            IntWrapper(1),
            IntWrapper(2),
        )
        assertThat(mapper.writeValueAsString(container))
            .isEqualTo("{\"a\":1,\"changed\":2}")
    }
}

data class Container(
    val a: IntWrapper,
    @JsonProperty("changed")
    val b: IntWrapper,
)

@JvmInline
value class IntWrapper(val value: Int)

Expected behavior

Expected :{"a":1,"changed":2}
Actual   :{"a":1,"b":2}

Versions
Kotlin: 1.6.0
Jackson-module-kotlin: 2.13.1
Jackson-databind: 2.13.1

@matek2305 matek2305 added the bug label Jan 12, 2022
@TheRishka
Copy link

Hey @matek2305 ! I have the same issues, there's clearly something wrong.
As a temporary fix, you could add field to the JsonProperty annotation. Works for me in that case. @field:JsonProperty

@k163377
Copy link
Contributor

k163377 commented Jan 21, 2023

For those who came later:
Annotation of Jackson on functions containing value class will not work, so please specify get or field if possible.
The causes of this problem are summarized here.
ProjectMapK/jackson-module-kogera#46

@k163377
Copy link
Contributor

k163377 commented Mar 18, 2023

I have submitted a summary of the root cause of this problem and how to address it as #651.
Progress will be managed there and this issue will be closed.

@k163377 k163377 closed this as completed Mar 18, 2023
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