Description
When serializing objects with a Mapper which has a bunch of setIgnoreFieldsForType configs, only the first matching class gets its properties removed for serializing in BaseAccessMode. These fieldsToRemove are stored in a HashMap, which doesn't guarantee order, so repeating classes from more to less specific is not reliable to ensure all desired fields are ignored. Below, you can see why: I marked the line which causes the sanitize method to stop too soon. I expect all classes in the fieldsToRemove map to be looped and used to sanitize. I added a test in attachment to reproduce this issue. Unfortunately, my project does not allow using Annotations to reach the expected behavior, as 90+% of the objects are being generated.
Note: the output of my test even changes depending on the order in which the 2 calls to setIgnoreFieldsForType are added.
private <T> Map<String, T> sanitize(final Class<?> type, final Map<String, T> delegate) {
for (final Map.Entry<Class<?>, String[]> entry : fieldsToRemove.entrySet()) {
if (entry.getKey().isAssignableFrom(type)) {
for (final String field : entry.getValue())
return delegate;
}
}
return delegate;
}