Skip to content

Jackson 3 does not auto-detect getters/setters that not have capital letter following "set"/"get" prefix (like getxFieldHint()) #5712

@tkrah

Description

@tkrah

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Hi,

I am using jackson 3.0.4 and 3.1.0 and it fails to deserialize properties which are somewhat special in terms of section 8.8 of the bean spec.

If you have a property xFieldHint the Getters and Setters have their first value lower-cased, instead of usually upper-cased.
But Jackson fails to read that - instead of getxFieldHint / setxFieldHint you must use getXFieldHint / setXFieldHint - imho this is wrong, that breaks a lot of code which works with Jackson 2 and e.g. eclipse / IntelliJ ([0]) have the same convention from the spec to have a lower case letter here.

Example:

import org.junit.jupiter.api.Test;

import tools.jackson.databind.json.JsonMapper;

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

public class Jackson3Test {

	public static class Pojo {
		private String xFieldHint;

		public String getxFieldHint() {
			return xFieldHint;
		}

		public void setxFieldHint(String xFieldHint) {
			this.xFieldHint = xFieldHint;
		}
	}

	@Test
	void test() {
		final JsonMapper mapper = JsonMapper.builder().build();
		final Pojo pojo = mapper.readValue("""
			{ "xFieldHint" : "test" }
			""", Pojo.class);
		assertThat(pojo.getxFieldHint()).isEqualTo("test");
	}
}

That should work imho, but it does not.

[0] https://github.com/JetBrains/intellij-community/blob/2247153ca4c2073591785e1854e9a35f1b513010/platform/util/src/com/intellij/openapi/util/text/StringUtil.java#L981

Version Information

3.0.4 / 3.1.0

Reproduction

See above.

Expected behavior

Example above should work.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    works-as-intendedFor issues closed due to (new) behavior observed is as intended and not a flaw

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions