Java 类org.codehaus.jackson.map.ser.FilterProvider 实例源码

项目:artifactory    文件:JsonUtil.java   
/**
 * jsonToString exclude null data end edit fields
 *
 * @param model - model data to String
 * @return - model data with json format
 */
public static String jsonToStringIgnoreSpecialFields(RestModel model) {
    String[] ExcludedFieldsFromView = getExcludedFields(model);
    ObjectMapper specialMapper = new ObjectMapper();
    specialMapper.setSerializationInclusion(JsonSerialize.Inclusion.NON_NULL);
    String data = null;
    FilterProvider filters = new SimpleFilterProvider()
            .addFilter("exclude fields",
                    SimpleBeanPropertyFilter.serializeAllExcept(
                            (ExcludedFieldsFromView)));
    ObjectWriter writer = specialMapper.writer(filters);
    try {
        data = writer.writeValueAsString(model);
    } catch (IOException e) {
        log.debug(e.getMessage());
    }
    return data;
}
项目:community-edition-old    文件:JsonJacksonTests.java   
@Test
public void testSerializeComment() throws IOException
{
    final Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    jsonHelper.withWriter(out, new Writer()
    {
        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
                    throws JsonGenerationException, JsonMappingException, IOException
        {
            FilterProvider fp = new SimpleFilterProvider().addFilter(
                        JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, aComment);
        }
    });
    assertTrue(out.toString().contains("{\"content\":\"<b>There it is</b>\""));
}
项目:community-edition-old    文件:JsonJacksonTests.java   
@Test
public void testNullInComment() throws IOException
{
    final Comment aComment = new Comment();
    aComment.setContent(null);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    jsonHelper.withWriter(out, new Writer()
    {
        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
                    throws JsonGenerationException, JsonMappingException, IOException
        {
            FilterProvider fp = new SimpleFilterProvider().addFilter(
                        JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, aComment);
        }
    });
    assertEquals("Null values should not be output.", "{\"canEdit\":false,\"canDelete\":false}",
                out.toString());
}
项目:cananolab    文件:ViewFilterUtil.java   
/**
 * Get an inclusive jackson object writer for writing a set of named fields of an object
 * 
 * @param includeFieldNames fields that should be serialized    
 * @param filterName filter name. This needs to match the @JsonFilter("filterName") annotation for a bean
 * 
 * @return a Jackson ObjectWriter
 * @throws Exception
 */
public static ObjectWriter getInclusiveObjectWriter(String[] includeFieldNames, String filterName) 
throws Exception {

    if (includeFieldNames == null)
        throw new Exception("includeFieldNames can't be null");

    if (filterName == null)
        throw new Exception("filterName can't be null");

    ObjectMapper mapper = new ObjectMapper();  
    FilterProvider filters = new SimpleFilterProvider()  
      .addFilter(filterName,   
          SimpleBeanPropertyFilter.filterOutAllExcept(includeFieldNames));  
    return mapper.writer(filters);  

}
项目:cananolab    文件:ViewFilterUtil.java   
/**
 * Get an exclusive jackson object writer for serializing an object without a set of named fields
 * 
 * @param excludeFieldNames fields that should be excluded for serialization
 * @param filterName filter name. This needs to match the @JsonFilter("filterName") annotation for a bean
 * 
 * @return a Jackson ObjectWriter
 * @throws Exception
 */
public static ObjectWriter getExclusivObjectWriter(String[] excludeFieldNames, String filterName) 
        throws Exception {
    if (excludeFieldNames == null)
        throw new Exception("includeFieldNames can't be null");

    if (filterName == null)
        throw new Exception("filterName can't be null");

    ObjectMapper mapper = new ObjectMapper();  
    FilterProvider filters = new SimpleFilterProvider()  
      .addFilter(filterName,   
          SimpleBeanPropertyFilter.serializeAllExcept(excludeFieldNames));  
    return mapper.writer(filters);  

}
项目:screensaver    文件:PlateReaderRawDataTransformer.java   
/**
 * Serialize to a JSON representation using 
 * {@link ObjectMapper#writeValue(java.io.Writer, Object)}
 * 
 * @return a JSON representation
 * @throws IOException
 */
public String serialize() throws IOException
{
  ObjectMapper mapper = new ObjectMapper();
  FilterProvider filters = new SimpleFilterProvider().addFilter(
      "savedForm1Properties",
      SimpleBeanPropertyFilter.filterOutAllExcept(
          "plates",
          "assayPlateSize",
          "outputFileName",
          "outputFormat",
          "assayPositiveControls",
          "assayNegativeControls",
          "assayOtherControls",
          "libraryControls"));
  return mapper.writer(filters).writeValueAsString(this);
}
项目:community-edition-old    文件:JsonJacksonTests.java   
@Test
public void testSerializeMultipleObjects() throws IOException
{
    final Collection<Comment> allComments = new ArrayList<Comment>();
    Comment aComment = new Comment();
    aComment.setContent("<b>There it is</b>");
    allComments.add(aComment);
    aComment = new Comment();
    aComment.setContent("<p>I agree with the author</p>");
    allComments.add(aComment);

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    jsonHelper.withWriter(out, new Writer()
    {
        @Override
        public void writeContents(JsonGenerator generator, ObjectMapper objectMapper)
                    throws JsonGenerationException, JsonMappingException, IOException
        {
            FilterProvider fp = new SimpleFilterProvider().addFilter(
                        JacksonHelper.DEFAULT_FILTER_NAME, new ReturnAllBeanProperties());
            objectMapper.writer(fp).writeValue(generator, allComments);
        }
    });
    assertTrue(out.toString().contains("content\":\"<b>There it is</b>"));
    assertTrue(out.toString().contains("content\":\"<p>I agree with the author</p>"));
}
项目:test-html-generator-plugin    文件:BeanSerializerBase.java   
/**
 * Helper method used to locate filter that is needed, based on filter id
 * this serializer was constructed with.
 * 
 * @since 1.7
 */
protected BeanPropertyFilter findFilter(SerializerProvider provider)
    throws JsonMappingException
{
    final Object filterId = _propertyFilterId;
    FilterProvider filters = provider.getFilterProvider();
    // Not ok to miss the provider, if a filter is declared to be needed.
    if (filters == null) {
        throw new JsonMappingException("Can not resolve BeanPropertyFilter with id '"+filterId+"'; no FilterProvider configured");
    }
    BeanPropertyFilter filter = filters.findFilter(filterId);
    // But whether unknown ids are ok just depends on filter provider; if we get null that's fine
    return filter;
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
protected SerializationConfig(SerializationConfig paramSerializationConfig, FilterProvider paramFilterProvider)
{
  super(paramSerializationConfig);
  this._featureFlags = paramSerializationConfig._featureFlags;
  this._serializationInclusion = paramSerializationConfig._serializationInclusion;
  this._serializationView = paramSerializationConfig._serializationView;
  this._filterProvider = paramFilterProvider;
}
项目:screensaver    文件:PlateReaderRawDataTransformer.java   
/**
 * Serialize to a JSON representation using 
 * {@link ObjectMapper#writeValue(java.io.Writer, Object)}
 * 
 * @return a JSON representation
 * @throws IOException
 */
public String serialize() throws IOException
{
  ObjectMapper mapper = new ObjectMapper();
  FilterProvider filters = new SimpleFilterProvider().addFilter(
      "savedForm2Properties",
      SimpleBeanPropertyFilter.filterOutAllExcept("uploadedFilename",
          "conditions",
          "replicates",
          "readoutTypeSelection",
          "readouts",
          "collationOrderOrdering"));
  return mapper.writer(filters).writeValueAsString(this);
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
protected SerializationConfig(SerializationConfig paramSerializationConfig, FilterProvider paramFilterProvider)
{
  super(paramSerializationConfig);
  this._featureFlags = paramSerializationConfig._featureFlags;
  this._serializationInclusion = paramSerializationConfig._serializationInclusion;
  this._serializationView = paramSerializationConfig._serializationView;
  this._filterProvider = paramFilterProvider;
}
项目:ingress-indonesia-dev    文件:BeanSerializerBase.java   
protected BeanPropertyFilter findFilter(SerializerProvider paramSerializerProvider)
{
  Object localObject = this._propertyFilterId;
  FilterProvider localFilterProvider = paramSerializerProvider.getFilterProvider();
  if (localFilterProvider == null)
    throw new JsonMappingException("Can not resolve BeanPropertyFilter with id '" + localObject + "'; no FilterProvider configured");
  return localFilterProvider.findFilter(localObject);
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
public FilterProvider getFilterProvider()
{
  return this._filterProvider;
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
public SerializationConfig withFilters(FilterProvider paramFilterProvider)
{
  return new SerializationConfig(this, paramFilterProvider);
}
项目:12306-android-Decompile    文件:ObjectMapper.java   
public ObjectWriter filteredWriter(FilterProvider paramFilterProvider)
{
  return new ObjectWriter(this, copySerializationConfig().withFilters(paramFilterProvider));
}
项目:12306-android-Decompile    文件:ObjectMapper.java   
public void setFilters(FilterProvider paramFilterProvider)
{
  this._serializationConfig = this._serializationConfig.withFilters(paramFilterProvider);
}
项目:12306-android-Decompile    文件:SerializerProvider.java   
public final FilterProvider getFilterProvider()
{
  return this._config.getFilterProvider();
}
项目:12306-android-Decompile    文件:ObjectWriter.java   
public ObjectWriter withFilters(FilterProvider paramFilterProvider)
{
  if (paramFilterProvider == this._config.getFilterProvider())
    return this;
  return new ObjectWriter(this, this._config.withFilters(paramFilterProvider));
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
public FilterProvider getFilterProvider()
{
  return this._filterProvider;
}
项目:12306-android-Decompile    文件:SerializationConfig.java   
public SerializationConfig withFilters(FilterProvider paramFilterProvider)
{
  return new SerializationConfig(this, paramFilterProvider);
}
项目:12306-android-Decompile    文件:ObjectMapper.java   
public ObjectWriter filteredWriter(FilterProvider paramFilterProvider)
{
  return new ObjectWriter(this, copySerializationConfig().withFilters(paramFilterProvider));
}
项目:12306-android-Decompile    文件:ObjectMapper.java   
public void setFilters(FilterProvider paramFilterProvider)
{
  this._serializationConfig = this._serializationConfig.withFilters(paramFilterProvider);
}
项目:12306-android-Decompile    文件:SerializerProvider.java   
public final FilterProvider getFilterProvider()
{
  return this._config.getFilterProvider();
}
项目:12306-android-Decompile    文件:ObjectWriter.java   
public ObjectWriter withFilters(FilterProvider paramFilterProvider)
{
  if (paramFilterProvider == this._config.getFilterProvider())
    return this;
  return new ObjectWriter(this, this._config.withFilters(paramFilterProvider));
}
项目:ingress-indonesia-dev    文件:SerializationConfig.java   
public FilterProvider getFilterProvider()
{
  return this._filterProvider;
}
项目:ingress-indonesia-dev    文件:SerializerProvider.java   
public final FilterProvider getFilterProvider()
{
  return this._config.getFilterProvider();
}