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

When Include.NON_DEFAULT setting is used on POJO record, empty values are not included in json if default is null #4893

Open
1 task done
xehonk opened this issue Jan 9, 2025 · 2 comments
Labels
to-evaluate Issue that has been received but not yet evaluated

Comments

@xehonk
Copy link

xehonk commented Jan 9, 2025

Search before asking

  • I searched in the issues and found nothing similar.

Describe the bug

Same issue as in #4741, but happens when the target is a record instead of a class.
Empty Strings/objects are not included in json output if NON_DEFAULT annotation is used on a record and the default value is null.

Version Information

2.18.1, 2.18.2

Reproduction

class JacksonTest {

	@JsonInclude(Include.NON_DEFAULT)
	record Record(String property) {}

	@JsonInclude(Include.NON_DEFAULT)
	@AllArgsConstructor
	@NoArgsConstructor
	@Getter
	static class NonRecord {
		private String property;
	}

	@Test
	void test() throws JsonProcessingException {
		ObjectMapper mapper = new ObjectMapper();

		assertThat(mapper.writeValueAsString(new Record("")))
			.isEqualTo(mapper.writeValueAsString(new NonRecord("")));
	}
}
expected: "{"property":""}"
 but was: "{}"

Expected behavior

No response

Additional context

No response

@xehonk xehonk added the to-evaluate Issue that has been received but not yet evaluated label Jan 9, 2025
@JooHyukKim
Copy link
Member

Did your test ever pass in previous versions?
As you know, record classes and regular POJO's are quite different and may behave differently.

@xehonk
Copy link
Author

xehonk commented Jan 28, 2025

I finally got around to testing it: it does not work in 2.18 or 2.17

small repo with reproduction: https://github.com/xehonk/jackson-databind-4893

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