You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@johnzon.apache.org by "Haino (JIRA)" <ji...@apache.org> on 2018/07/02 17:37:00 UTC
[jira] [Created] (JOHNZON-176) setIgnoreFieldsForType does not keep
hierarchy in mind
Haino created JOHNZON-176:
-----------------------------
Summary: setIgnoreFieldsForType does not keep hierarchy in mind
Key: JOHNZON-176
URL: https://issues.apache.org/jira/browse/JOHNZON-176
Project: Johnzon
Issue Type: Improvement
Components: Mapper
Affects Versions: 1.1.8
Reporter: Haino
Attachments: JohnzonIgnoreTest.java
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 {color:#660e7a}fieldsToRemove{color} 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 {color:#660e7a}fieldsToRemove {color}{color:#333333}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.
{color}
{color:#333333}Note: the output of my test even changes depending on the order in which the 2 calls to setIgnoreFieldsForType are added.{color}
{color:#000080}private {color}<{color:#20999d}T{color}> Map<String, {color:#20999d}T{color}> sanitize({color:#000080}final {color}Class<?> type, {color:#000080}final {color}Map<String, {color:#20999d}T{color}> delegate) {
{color:#000080} for {color}({color:#000080}final {color}Map.Entry<Class<?>, String[]> entry : {color:#660e7a}fieldsToRemove{color}.entrySet()) {
{color:#000080}if {color}(entry.getKey().isAssignableFrom(type)) {
{color:#000080}for {color}({color:#000080}final {color}String field : entry.getValue()) {
delegate.remove(field);
}
-{color:#000080}return {color}delegate;-
}
}
{color:#000080}return {color}delegate;
}
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)