Skip to content

Ignored fields not consistently exposed via BeanDescription.getIgnoredPropertyNames() #3591

@odrotbohm

Description

@odrotbohm

The following test case fails, and I think it shouldn't:

public class SampleTest {

	@Test
	void sampleTest() {

		ObjectMapper mapper = new ObjectMapper();
		SerializationConfig config = mapper.getSerializationConfig();
		ClassIntrospector introspector = config.getClassIntrospector();
		BeanDescription description = introspector.forSerialization(config, mapper.constructType(Sample.class), config);

		description.findAnySetterAccessor(); // <1>

		assertThat(description.getIgnoredPropertyNames()).containsExactlyInAnyOrder("first", "second");
	}

	@JsonIgnoreProperties("second")
	@JsonAutoDetect(fieldVisibility = Visibility.ANY)
	public class Sample {
		@JsonIgnore String first;
		String second;
	}
}

Note that <1> is even necessary to trigger the property collection in the first place. If you do not call that method, _ignoredPropertyNames in the underlying POJOPropertiesCollector will not have been initialized.

Zooming out a bit, I would like to find out about all properties, that are ignored by Jackson for either serialization or deserialization. Jackson seems to expose API to find out, but that doesn't reflect what's actually annotated in the user's sources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.2property-discoveryProblem with property discovery (introspection)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions