[ 
https://issues.apache.org/jira/browse/JOHNZON-176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16530959#comment-16530959
 ] 

Haino commented on JOHNZON-176:
-------------------------------

Short answer: Yes, that's how I had it set up initially.


My main driver to log this was because of our architecture however: we have a 
LOT of objects all implementing an interface with a bunch of fields we don't 
want to serialize. That's why it would be easy to only specify these fields 
once in the ignore list, while still being able to add more specific fields for 
the implementing child classes. In my opinion, this allows more refinement, 
instead of having to repeat the same fields for every class while most only 
need to have these interface fields removed.

> 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
>            Priority: Major
>              Labels: newbie
>         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)

Reply via email to