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

Field proliferation bug when using ObjectMapper in Kotlin #772

Open
1 task done
Yaklede opened this issue Feb 22, 2024 · 1 comment
Open
1 task done

Field proliferation bug when using ObjectMapper in Kotlin #772

Yaklede opened this issue Feb 22, 2024 · 1 comment
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@Yaklede
Copy link

Yaklede commented Feb 22, 2024

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Field proliferation bug when using ObjectMapper in Kotlin

Version Information

2.15.3

Reproduction

<-- Any of the following

  1. Brief code sample/snippet: include here in preformatted/code section
  2. Longer example stored somewhere else (diff repo, snippet), add a link
  3. Textual explanation: include here
    -->
// Your code here

Here is the class information as follows.

data class MapperTest(
    @field:JsonProperty("tPhone")
    val tPhone: String,
    @field:JsonProperty("tData")
    val tData: String,
    @field:JsonProperty("tEmail")
    val tEmail: String,
)

If you convert using objectMapper to JSON in this state, it will look like this.

class ObjectMapperTest {
    private val objectMapper = ObjectMapper().registerKotlinModule().registerModules(JavaTimeModule())
    @Test
    fun test() {
        val request = MapperTest(
            tPhone = "phone",
            tData =  "data",
            tEmail =  "email"
        )
        val result = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(request)
        println(result)
    }
}
{
  "tPhone" : "phone",
  "tData" : "data",
  "tEmail" : "email",
  "tphone" : "phone",
  "tdata" : "data",
  "temail" : "email"
}

I have found where the issue lies.

I was able to find the issue within the collectAll() method in the POJOPropertiesCollector.class.

image

In the following state, when the _addMethods() method is called, the number of properties increases to six.
image

In my opinion, the issue seems to arise from the discrepancy between the names of the getter methods and the fields during the process of decompiling the Kotlin code into Java code.

I hope this bug report is helpful.

Expected behavior

No response

Additional context

No response

@Yaklede Yaklede added the to-evaluate Issue that has been received but not yet evaluated label Feb 22, 2024
@cowtowncoder
Copy link
Member

Kotlin-related, will transfer to Kotlin module repo.

@cowtowncoder cowtowncoder transferred this issue from FasterXML/jackson-databind Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to-evaluate Issue that has been received but not yet evaluated
Projects
None yet
Development

No branches or pull requests

2 participants