Skip to content

Wrong setter is used when deserializing from InputStream (or byte[]) #5372

@quaff

Description

@quaff

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Please see failed test.

Version Information

3.0.1

Reproduction

package com.demo;

import org.junit.jupiter.api.Test;
import tools.jackson.databind.json.JsonMapper;

import java.io.ByteArrayInputStream;

import static org.assertj.core.api.Assertions.assertThat;

class DeserializationTests {

    static JsonMapper jsonMapper = new JsonMapper();

    public static final String JSON = """
            {
              "aaaabbbbcccc": "v3",
              "aaaabbbbcccc2": "v4"
            }""";

    @Test
    void deserializeFromString() {
            TestObject testObject = jsonMapper.readValue(JSON, TestObject.class);
            assertThat(testObject.getAaaabbbbcccc2()).isEqualTo("v4");
    }

    @Test
    void deserializeFromInputStream() {
            TestObject testObject = jsonMapper.readValue(new ByteArrayInputStream(JSON.getBytes()), TestObject.class);
            assertThat(testObject.getAaaabbbbcccc2()).isEqualTo("v4"); // failed since setAaaabbbbcccc() called twice
    }

    static class TestObject {
        private String aaaabbbbcccc;
        private String aaaabbbbcccc2;

        public String getAaaabbbbcccc2() {
            return aaaabbbbcccc2;
        }

        public void setAaaabbbbcccc2(String aaaabbbbcccc2) {
            this.aaaabbbbcccc2 = aaaabbbbcccc2;
        }

        public String getAaaabbbbcccc() {
            return aaaabbbbcccc;
        }

        public void setAaaabbbbcccc(String aaaabbbbcccc) {
            this.aaaabbbbcccc = aaaabbbbcccc;
        }
    }
}
plugins {
	java
}

group = "com.example.ai"
version = "0.0.1-SNAPSHOT"

java {
	version = 21
}

repositories {
	mavenCentral()
}

dependencies {
	implementation("tools.jackson.core:jackson-databind:3.0.1")
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.14.0")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.14.0")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.14.0")
    testImplementation("org.assertj:assertj-core:3.27.6")
}

tasks.withType<Test> {
	useJUnitPlatform()
}

Expected behavior

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.0Issue planned for initial 3.0 release

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions