-
Notifications
You must be signed in to change notification settings - Fork 174
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
Add KotlinPropertyNameAsImplicitName option #686
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
093842d
Add UseKotlinPropertyNameForGetter option
k163377 3dd5407
Separate conventional processing into function
k163377 cbbcfbe
Implement getting from Kotlin property name
k163377 5b65f56
Add tests for #630
k163377 aa7217f
Fix for review
k163377 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/com/fasterxml/jackson/module/kotlin/test/github/Github630.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.fasterxml.jackson.module.kotlin.test.github | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.module.kotlin.KotlinFeature | ||
import com.fasterxml.jackson.module.kotlin.KotlinModule | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
|
||
class Github630 { | ||
private val mapper = ObjectMapper() | ||
.registerModule(KotlinModule.Builder().enable(KotlinFeature.UseKotlinPropertyNameForGetter).build())!! | ||
|
||
data class Dto( | ||
// from #570, #603 | ||
val FOO: Int = 0, | ||
val bAr: Int = 0, | ||
@JsonProperty("b") | ||
val BAZ: Int = 0, | ||
@JsonProperty("q") | ||
val qUx: Int = 0, | ||
// from #71 | ||
internal val quux: Int = 0, | ||
// from #434 | ||
val `corge-corge`: Int = 0, | ||
// additional | ||
@get:JvmName("aaa") | ||
val grault: Int = 0 | ||
) | ||
|
||
@Test | ||
fun test() { | ||
val dto = Dto() | ||
|
||
assertEquals( | ||
"""{"FOO":0,"bAr":0,"b":0,"q":0,"quux":0,"corge-corge":0,"grault":0}""", | ||
mapper.writeValueAsString(dto) | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cowtowncoder
I would like to get a review as I am not sure about the option name and description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One quick question: is "property" first-class concept in Kotlin? If not, maybe it'd be "field", but I assume it is.
But I guess I am not sure what "use property name for getter" actually means... I mean, getter in Jackson specifically means method use to access value of a logical property to serialize. It has name specified by class file, and does not change.
Name of logical property does change tho. So maybe naming here is bit confusing, at least to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can call it a first-class concept in this regard.
On
Kotlin
, fields and accessors are defined for properties.https://kotlinlang.org/docs/properties.html
I don't know if this is a good name, but at least this is how I would describe the internal behavior directly.
If the emphasis is on naming on
Jackson
, would it beUseKotrinPropertyNameForGetterImplicitName
?However, it doesn't seem like a good name since we may not use the
findImplicitPropertyName
function forever.Also, the name seems too long compared to the traditional
KotlinFeature
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just did not understand what "for getter" means. But yes, if it changes "implicit [property] name" in context of serialization, I can see how "....ForGetterImplicitName" could work.
Does this not affect deserialization? Otherwise just something like "UseKotlinNameAsImplicitName" would make more sense to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to express that it does not affect parameters, fields, or setters, but only getters.
Currently we are already using names on
Kotlin
for parameter names, but that is not affected by this option.If there are annotations for deserialization on the
getter
, it will affect the behavior, but basically it should only affect serialization.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I think referring to serialization makes more sense because getter really is physical thing (Method) used to access a property for purpose of (de)serialization. So you can't really change name of getter, but you change name of property for (de)serialization. Although, yes, obtained from getter method.
Still, ultimately this is your decision: I just offer my suggestions. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed for correction.
aa7217f