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

项目: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;
}
项目: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);
}
项目:homePi    文件:HomePiUserTestFilter.java   
public void serializeAsField(Object bean, JsonGenerator jGen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception {

    if(bean instanceof HomePiUser){
        HomePiUser user = (HomePiUser)bean;
        Set<String> filterFields = new HashSet<String>();
     filterFields.add("userName");
     filterFields.add("email");
     filterFields.add("locale");
     filterFields.add("picLink");
     filterFields.add("givenName");
     filterFields.add("familyName");
     filterFields.add("fullName");

        SimpleBeanPropertyFilter.filterOutAllExcept(filterFields).serializeAsField(bean, jGen, provider, writer);
    } 
}
项目: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);
}
项目:homePi    文件:LogDataTestFilter.java   
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov, BeanPropertyWriter writer) throws Exception {
    if (bean instanceof LogData) {
        Set<String> filterFields = new HashSet<String>();
        filterFields.add("logKey");
        filterFields.add("logMessage");
        filterFields.add("createTime");
        filterFields.add("logTypeId");

        SimpleBeanPropertyFilter.filterOutAllExcept(filterFields).serializeAsField(bean, jgen, prov, writer);
    }
}
项目:homePi    文件:PiProfileTestFilter.java   
public void serializeAsField(Object bean, JsonGenerator jGen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception {

    if (bean instanceof PiProfile) {
        Set<String> filterFields = new HashSet<String>();
        filterFields.add("ipAddress");
        filterFields.add("name");
        filterFields.add("sshPortNumber");
        filterFields.add("piSerialId");
        filterFields.add("apiKey");

        SimpleBeanPropertyFilter.filterOutAllExcept(filterFields).serializeAsField(bean, jGen, provider, writer);
    }
}
项目:homePi    文件:ManagedAppTestFilter.java   
public void serializeAsField(Object bean, JsonGenerator jGen, SerializerProvider provider, BeanPropertyWriter writer) throws Exception {

    if (bean instanceof ManagedApp) {
        Set<String> filterFields = new HashSet<String>();
        filterFields.add("versionNumber");
        filterFields.add("appName");
        filterFields.add("fileName");
        filterFields.add("deploymentPath");

        SimpleBeanPropertyFilter.filterOutAllExcept(filterFields).serializeAsField(bean, jGen, provider, writer);
    }
}