Example usage for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider

List of usage examples for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.ser.impl SimpleFilterProvider SimpleFilterProvider.

Prototype

public SimpleFilterProvider() 

Source Link

Usage

From source file:ob.servlet.getuserinfo.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods./*from w w  w.ja  v  a  2 s. co m*/
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    outinfo = null;
    String loginedUserName = (String) request.getSession().getAttribute("username");
    if (loginedUserName != null && !loginedUserName.equals("")) {
        int loginedUserid = (Integer) request.getSession().getAttribute("userid");
        po = dao.getinfo(loginedUserid);
        if (po != null) {
            if (po.getUsername().equals(loginedUserName)) {
                Iterator it = po.getTask().iterator();
                while (it.hasNext()) {
                    TaskPO taskpo = (TaskPO) it.next();
                    if (RunningTask.isHere(taskpo.getTid())) {
                        taskpo.setIsrunning(true);
                        taskpo.setStatus(RunningTask.getStatus(taskpo.getTid()));
                    }
                }
                FilterProvider filters = new SimpleFilterProvider()
                        .addFilter("userFilter",
                                SimpleBeanPropertyFilter.serializeAllExcept("password", "log", "sms"))
                        .addFilter("taskFilter", SimpleBeanPropertyFilter.filterOutAllExcept("tid", "taskname",
                                "ctime", "status", "isrunning"));//?password
                outinfo = mapper.writer(filters).writeValueAsString(po);//JSON
            }
        }
    } else {
        outinfo = "false";//
    }
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        /* TODO output your page here. You may use following sample code. */
        out.print(outinfo);
    } finally {
        out.close();
    }
}

From source file:com.github.darwinevolution.darwin.jackson.JacksonEvolutionResultConsumer.java

@Override
public void consumeResults(ComparisonResult<T> comparisonResult,
        ResultConsumerConfiguration resultConsumerConfiguration) {
    try {// w ww . j a v a  2 s.  c  o  m
        SimpleFilterProvider fp = new SimpleFilterProvider();
        Set<String> includedFields = new HashSet<String>();
        includedFields.add("name");
        includedFields.add("implementationPreference");
        includedFields.add("timestamp");
        includedFields.add("resultType");
        includedFields.add("protoplastDurationNs");
        includedFields.add("evolvedDurationNs");

        if (comparisonResult.getResultType().isError()
                && resultConsumerConfiguration.shouldPrintDetailsOnError()) {
            includedFields.add("protoplastArguments");
            includedFields.add("protoplastValue");
            includedFields.add("protplastException");

            includedFields.add("evolvedArguments");
            includedFields.add("evolvedValue");
            includedFields.add("evolvedException");
        }

        if (resultConsumerConfiguration.shouldPrintBothArguments()) {
            includedFields.add("protoplastArguments");
            includedFields.add("evolvedArguments");
        }

        if (resultConsumerConfiguration.shouldPrintResults()) {
            includedFields.add("protoplastValue");
            includedFields.add("protplastException");
            includedFields.add("evolvedValue");
            includedFields.add("evolvedException");
        }

        fp.addFilter(FILTER_NAME, SimpleBeanPropertyFilter.filterOutAllExcept(includedFields));
        String json = objectMapper.writer(fp)
                .writeValueAsString(JsonComparisonResult.from(comparisonResult, resultConsumerConfiguration));
        evolutionLog.debug(json);
    } catch (JsonProcessingException e) {
        log.error("Error creating json comparison result", e);
    }
}

From source file:org.oncoblocks.centromere.web.util.FilteringJackson2HttpMessageConverter.java

@Override
protected void writeInternal(Object object, Type type, HttpOutputMessage outputMessage)
        throws IOException, HttpMessageNotWritableException {

    ObjectMapper objectMapper = getObjectMapper();
    JsonGenerator jsonGenerator = objectMapper.getFactory().createGenerator(outputMessage.getBody());

    try {/*  w w w  .  j  a v  a  2 s.  com*/

        if (this.prefixJson) {
            jsonGenerator.writeRaw(")]}', ");
        }

        if (object instanceof ResponseEnvelope) {

            ResponseEnvelope envelope = (ResponseEnvelope) object;
            Object entity = envelope.getEntity();
            Set<String> fieldSet = envelope.getFieldSet();
            Set<String> exclude = envelope.getExclude();
            FilterProvider filters = null;

            if (fieldSet != null && !fieldSet.isEmpty()) {
                if (entity instanceof ResourceSupport) {
                    fieldSet.add("content"); // Don't filter out the wrapped content.
                }
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.filterOutAllExcept(fieldSet))
                        .setFailOnUnknownId(false);
            } else if (exclude != null && !exclude.isEmpty()) {
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.serializeAllExcept(exclude))
                        .setFailOnUnknownId(false);
            } else {
                filters = new SimpleFilterProvider()
                        .addFilter("fieldFilter", SimpleBeanPropertyFilter.serializeAllExcept())
                        .setFailOnUnknownId(false);
            }

            objectMapper.setFilterProvider(filters);
            objectMapper.writeValue(jsonGenerator, entity);

        } else if (object == null) {
            jsonGenerator.writeNull();
        } else {
            FilterProvider filters = new SimpleFilterProvider().setFailOnUnknownId(false);
            objectMapper.setFilterProvider(filters);
            objectMapper.writeValue(jsonGenerator, object);
        }

    } catch (JsonProcessingException e) {
        e.printStackTrace();
        throw new HttpMessageNotWritableException("Could not write JSON: " + e.getMessage());
    }

}

From source file:com.getchute.android.photopickerplus.models.MediaModel.java

public String serializeImageDataModel() {
    FilterProvider filters = new SimpleFilterProvider().addFilter("imageDataModelFilter",
            SimpleBeanPropertyFilter.filterOutAllExcept("options", "media"));
    String result = null;//from w  w  w. j a  va 2s.  co m
    try {
        result = JsonUtil.getMapper().writer(filters).writeValueAsString(this);
    } catch (JsonProcessingException e) {
        ALog.d("", e);
    }
    return result;
}

From source file:com.groupon.odo.controllers.PathController.java

@SuppressWarnings("deprecation")
@RequestMapping(value = "/api/path", method = RequestMethod.GET)
public @ResponseBody String getPathsForProfile(Model model, String profileIdentifier,
        @RequestParam(value = "typeFilter[]", required = false) String[] typeFilter,
        @RequestParam(value = "clientUUID", defaultValue = Constants.PROFILE_CLIENT_DEFAULT_ID) String clientUUID)
        throws Exception {
    int profileId = ControllerUtils.convertProfileIdentifier(profileIdentifier);
    List<EndpointOverride> paths = PathOverrideService.getInstance().getPaths(profileId, clientUUID,
            typeFilter);/*from ww w. j  a v a  2 s.  c  o m*/

    HashMap<String, Object> jqReturn = Utils.getJQGridJSON(paths, "paths");

    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.addMixInAnnotations(Object.class, ViewFilters.GetPathFilter.class);
    String[] ignorableFieldNames = { "possibleEndpoints", "enabledEndpoints" };
    FilterProvider filters = new SimpleFilterProvider().addFilter(
            "Filter properties from the PathController GET",
            SimpleBeanPropertyFilter.serializeAllExcept(ignorableFieldNames));

    ObjectWriter writer = objectMapper.writer(filters);

    return writer.writeValueAsString(jqReturn);
}

From source file:eu.scape_project.cdx_creator.CDXCreationTask.java

public void createIndex() {
    FileInputStream fileInputStream = null;
    ArchiveReader reader = null;/*from   w  w w .  java2s  .co  m*/
    FileOutputStream outputStream = null;
    try {
        fileInputStream = new FileInputStream(archiveFile);
        reader = ArchiveReaderFactory.getReader(fileInputStream, this.archiveFileName);
        reader.setComputePayloadDigest(config.isCreatePayloadDigest());
        List<CdxArchiveRecord> cdxArchRecords = new ArrayList<CdxArchiveRecord>();
        while (reader.hasNext()) {
            ArchiveRecord archRec = (ArchiveRecord) reader.next();
            CdxArchiveRecord cdxArchRec = CdxArchiveRecord.fromArchiveRecord(archRec);
            cdxArchRec.setContainerFileName(archiveFileName);
            cdxArchRec.setContainerLengthStr(Long.toString(archiveFile.length()));
            cdxArchRecords.add(cdxArchRec);
        }

        CsvMapper mapper = new CsvMapper();
        mapper.setDateFormat(GMTGTechDateFormat);

        String cdxfileCsColumns = config.getCdxfileCsColumns();
        List<String> cdxfileCsColumnsList = Arrays.asList(cdxfileCsColumns.split("\\s*,\\s*"));
        String[] cdxfileCsColumnsArray = cdxfileCsColumnsList.toArray(new String[cdxfileCsColumnsList.size()]);

        CsvSchema.Builder builder = CsvSchema.builder();
        for (String cdxField : cdxfileCsColumnsList) {
            builder.addColumn(cdxField);
        }
        builder.setColumnSeparator(' ');
        CsvSchema schema = builder.build();
        schema = schema.withoutQuoteChar();

        SimpleFilterProvider filterProvider = new SimpleFilterProvider().addFilter("cdxfields",
                FilterExceptFilter.filterOutAllExcept(cdxfileCsColumnsArray));

        ObjectWriter cdxArchRecordsWriter = mapper.writer(filterProvider).withSchema(schema);

        PrintStream pout = null;
        String outputPathStr = config.getOutputStr();
        if (outputPathStr != null) {
            FileOutputStream fos;
            try {
                fos = new FileOutputStream(outputPathStr, true);
                pout = new PrintStream(fos);
                System.setOut(pout);
            } catch (FileNotFoundException ex) {
                LOG.error("File not found error", ex);
            }
        }
        System.out.println(" " + config.getCdxfileCsHeader());

        cdxArchRecordsWriter.writeValue(System.out, cdxArchRecords);

        if (pout != null) {
            pout.close();
        }

    } catch (FileNotFoundException ex) {
        LOG.error("File not found error", ex);
    } catch (IOException ex) {
        LOG.error("I/O Error", ex);
    } finally {
        try {
            if (fileInputStream != null) {
                fileInputStream.close();
            }

            if (outputStream != null) {
                outputStream.close();
            }

        } catch (IOException ex) {
            LOG.error("I/O Error", ex);
        }
    }
}

From source file:de.brendamour.jpasskit.signing.PKAbstractSIgningUtil.java

protected ObjectWriter configureObjectMapper(final ObjectMapper jsonObjectMapper) {
    jsonObjectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
    jsonObjectMapper.setDateFormat(new ISO8601DateFormat());

    SimpleFilterProvider filters = new SimpleFilterProvider();

    // haven't found out, how to stack filters. Copying the validation one for now.
    filters.addFilter("validateFilter",
            SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors"));
    filters.addFilter("pkPassFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors",
            "foregroundColorAsObject", "backgroundColorAsObject", "labelColorAsObject", "passThatWasSet"));
    filters.addFilter("barcodeFilter", SimpleBeanPropertyFilter.serializeAllExcept("valid", "validationErrors",
            "messageEncodingAsString"));
    filters.addFilter("charsetFilter", SimpleBeanPropertyFilter.filterOutAllExcept("name"));
    jsonObjectMapper.setSerializationInclusion(Include.NON_NULL);
    jsonObjectMapper.addMixIn(Object.class, ValidateFilterMixIn.class);
    jsonObjectMapper.addMixIn(PKPass.class, PkPassFilterMixIn.class);
    jsonObjectMapper.addMixIn(PKBarcode.class, BarcodeFilterMixIn.class);
    jsonObjectMapper.addMixIn(Charset.class, CharsetFilterMixIn.class);
    return jsonObjectMapper.writer(filters);
}

From source file:com.arpnetworking.logback.StenoEncoder.java

StenoEncoder(final JsonFactory jsonFactory, final ObjectMapper objectMapper) {

    // Initialize object mapper;
    _objectMapper = objectMapper;/*from w ww.j a  va  2  s.c  om*/
    _objectMapper.setAnnotationIntrospector(new StenoAnnotationIntrospector());
    final SimpleFilterProvider simpleFilterProvider = new SimpleFilterProvider();
    simpleFilterProvider.addFilter(RedactionFilter.REDACTION_FILTER_ID,
            new RedactionFilter(!DEFAULT_REDACT_NULL));
    // Initialize this here based on the above code, if it was initialized at the declaration site then things
    // could get out of sync
    _redactEnabled = true;
    _objectMapper.setFilters(simpleFilterProvider);

    // Setup writing of Date/DateTime values
    _objectMapper.registerModule(new JodaModule());
    _objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
    _objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
    _objectMapper.setDateFormat(new ISO8601DateFormat());

    // Setup other common modules
    _objectMapper.registerModule(new AfterburnerModule());
    _objectMapper.registerModule(new Jdk7Module());
    _objectMapper.registerModule(new Jdk8Module());
    _objectMapper.registerModule(new GuavaModule());

    // Serialization strategies
    _listsSerialziationStrategy = new ListsSerialziationStrategy(this, jsonFactory, _objectMapper);
    _objectAsJsonSerialziationStrategy = new ObjectAsJsonSerialziationStrategy(this, jsonFactory,
            _objectMapper);
    _objectSerialziationStrategy = new ObjectSerialziationStrategy(this, jsonFactory, _objectMapper);
    _mapOfJsonSerialziationStrategy = new MapOfJsonSerialziationStrategy(this, jsonFactory, _objectMapper);
    _mapSerialziationStrategy = new MapSerialziationStrategy(this, jsonFactory, _objectMapper);
    _arrayOfJsonSerialziationStrategy = new ArrayOfJsonSerialziationStrategy(this, jsonFactory, _objectMapper);
    _arraySerialziationStrategy = new ArraySerialziationStrategy(this, jsonFactory, _objectMapper);
    _standardSerializationStrategy = new StandardSerializationStrategy(this, jsonFactory, _objectMapper);
}

From source file:org.osiam.resource_server.resources.helper.AttributesRemovalHelper.java

private ObjectWriter getObjectWriter(ObjectMapper mapper, String[] fieldsToReturn) {

    if (fieldsToReturn.length != 0) {
        mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);

        HashSet<String> givenFields = new HashSet<String>();
        givenFields.add("schemas");
        for (String field : fieldsToReturn) {
            givenFields.add(field);//from  w ww .  j  a  v a2 s. c o  m
        }
        String[] finalFieldsToReturn = givenFields.toArray(new String[givenFields.size()]);

        FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name",
                SimpleBeanPropertyFilter.filterOutAllExcept(finalFieldsToReturn));
        return mapper.writer(filters);
    }
    return mapper.writer();
}

From source file:org.osiam.resources.helper.AttributesRemovalHelper.java

private ObjectWriter getObjectWriter(ObjectMapper mapper, String[] fieldsToReturn) {

    if (fieldsToReturn.length != 0) {
        mapper.addMixInAnnotations(Object.class, PropertyFilterMixIn.class);

        HashSet<String> givenFields = new HashSet<>();
        givenFields.add("schemas");
        Collections.addAll(givenFields, fieldsToReturn);
        String[] finalFieldsToReturn = givenFields.toArray(new String[givenFields.size()]);

        FilterProvider filters = new SimpleFilterProvider().addFilter("filter properties by name",
                SimpleBeanPropertyFilter.filterOutAllExcept(finalFieldsToReturn));
        return mapper.writer(filters);
    }/*w  w  w . j  a v a2  s . c  om*/
    return mapper.writer();
}