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

Jackson produces invalid field names from Kotlin value classes #462

Closed
kevinstembridge opened this issue Jun 7, 2021 · 3 comments
Closed
Labels

Comments

@kevinstembridge
Copy link

kevinstembridge commented Jun 7, 2021

This may well be an issue on the Kotlin side, but when a Kotlin class has a property that is one of the new @JvmInline value classes, Jackson converts it to JSON with a weird suffix on the field name.

e.g.

@JvmInline
value class ModelName(val value: String)
data class MyDto(val modelName: ModelName)

Jackson will produce JSON that looks like this:

{
    "modelName-11MJ8YI": "Some Model Name"
}

I've tried adding a @JsonProperty("modelName") annotation but it doesn't make a difference.

UPDATE: I found this comment on a previous issue:
#413 (comment)

Using @get:JsonProperty instead of @JsonProperty fixes (or works around) this issue.

I'll leave this issue open in case you think there is something that can be done on the Jackson side to handle these inline field names without having to use the extra annotation.

@dinomite
Copy link
Member

dinomite commented Jun 9, 2021

Ahh yes, it seems we have some work to do around value classes. That postfix (-11MJ8YI) is generated by the Kotlin compiler. I think in this case they act as bridge methods to the true accessors, which means the annotations aren't present and we'll have to infer (read: guess at) the base method to find annotations or just what the method should be, sans postfix.

Could you make a minimal reproduction example? You could make a PR against 2.13 and add a test which would help us get this fixed.

@kevinstembridge
Copy link
Author

My apologies. I've wasted your time. I was using an older version of Jackson.

I forked and started creating a test but came across an existing test for this exact problem.

This issue was fixed in #356.

Sorry for the trouble.

@dinomite
Copy link
Member

dinomite commented Jun 9, 2021

Thanks for the update, that's a great outcome for us all!

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

2 participants