Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.fasterxml.jackson.databind.ser.impl;
  
Decorated com.fasterxml.jackson.databind.ser.BeanPropertyWriter that will filter out properties that are not to be included in currently active JsonView.
 
 public abstract class FilteredBeanPropertyWriter
 {    
     public static BeanPropertyWriter constructViewBased(BeanPropertyWriter baseClass<?>[] viewsToIncludeIn)
     {
         if (viewsToIncludeIn.length == 1) {
             return new SingleView(baseviewsToIncludeIn[0]);
         }
         return new MultiView(baseviewsToIncludeIn);
     }
 
     /*
     /**********************************************************
     /* Concrete sub-classes
     /**********************************************************
      */
 
     private final static class SingleView
         extends BeanPropertyWriter
     {
         protected final BeanPropertyWriter _delegate;
 
         protected final Class<?> _view;
         
         protected SingleView(BeanPropertyWriter delegateClass<?> view)
         {
             super(delegate);
              = delegate;
              = view;
         }
 
         @Override
         public SingleView rename(NameTransformer transformer) {
             return new SingleView(.rename(transformer), );
         }
         
         @Override
         public void assignSerializer(JsonSerializer<Objectser) {
             .assignSerializer(ser);
         }
 
         @Override
         public void assignNullSerializer(JsonSerializer<ObjectnullSer) {
             .assignNullSerializer(nullSer);
         }
         
         @Override
         public void serializeAsField(Object beanJsonGenerator jgenSerializerProvider prov)
             throws Exception
         {
             Class<?> activeView = prov.getActiveView();
             if (activeView == null || .isAssignableFrom(activeView)) {
                 .serializeAsField(beanjgenprov);
             }
         }
 
         @Override
         public void serializeAsColumn(Object beanJsonGenerator jgenSerializerProvider prov)
             throws Exception
         {
             Class<?> activeView = prov.getActiveView();
             if (activeView == null || .isAssignableFrom(activeView)) {
                 .serializeAsColumn(beanjgenprov);
             } else {
                 .serializeAsPlaceholder(beanjgenprov);
             }
         }
     }
 
     private final static class MultiView
         extends BeanPropertyWriter
     {
         protected final BeanPropertyWriter _delegate;
 
         protected final Class<?>[] _views;
         
         protected MultiView(BeanPropertyWriter delegateClass<?>[] views) {
             super(delegate);
              = delegate;
              = views;
         }
 
         @Override
         public MultiView rename(NameTransformer transformer) {
             return new MultiView(.rename(transformer), );
         }
         
         @Override
        public void assignSerializer(JsonSerializer<Objectser) {
            .assignSerializer(ser);
        }
        @Override
        public void assignNullSerializer(JsonSerializer<ObjectnullSer) {
            .assignNullSerializer(nullSer);
        }
        
        @Override
        public void serializeAsField(Object beanJsonGenerator jgenSerializerProvider prov)
            throws Exception
        {
            final Class<?> activeView = prov.getActiveView();
            if (activeView != null) {
                int i = 0, len = .;
                for (; i < len; ++i) {
                    if ([i].isAssignableFrom(activeView)) break;
                }
                // not included, bail out:
                if (i == len) {
                    return;
                }
            }
            .serializeAsField(beanjgenprov);
        }
        @Override
        public void serializeAsColumn(Object beanJsonGenerator jgenSerializerProvider prov)
            throws Exception
        {
            final Class<?> activeView = prov.getActiveView();
            if (activeView != null) {
                int i = 0, len = .;
                for (; i < len; ++i) {
                    if ([i].isAssignableFrom(activeView)) break;
                }
                // not included, bail out:
                if (i == len) {
                    .serializeAsPlaceholder(beanjgenprov);
                    return;
                }
            }
            .serializeAsColumn(beanjgenprov);
        }
    }
New to GrepCode? Check out our FAQ X