Uploaded image for project: 'Johnzon'
  1. Johnzon
  2. JOHNZON-176

setIgnoreFieldsForType does not keep hierarchy in mind

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.8
    • 1.1.9
    • Mapper

    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())

      {                 delegate.remove(field);             }

                  return delegate;
              }
           }
           return delegate;
      }

      Attachments

        Activity

          People

            romain.manni-bucau Romain Manni-Bucau
            HSens Haino
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: