Example usage for com.fasterxml.jackson.core.util DefaultPrettyPrinter DefaultPrettyPrinter

List of usage examples for com.fasterxml.jackson.core.util DefaultPrettyPrinter DefaultPrettyPrinter

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core.util DefaultPrettyPrinter DefaultPrettyPrinter.

Prototype

public DefaultPrettyPrinter() 

Source Link

Usage

From source file:org.apereo.services.persondir.AbstractPersonAttributeDaoTest.java

protected ObjectWriter getJsonWriter() {
    return this.mapper.writer(new DefaultPrettyPrinter());
}

From source file:com.ning.metrics.action.hdfs.data.Row.java

public String toJSON() throws IOException {
    final StringWriter s = new StringWriter();
    final JsonGenerator generator = new JsonFactory().createJsonGenerator(s);
    generator.setPrettyPrinter(new DefaultPrettyPrinter());
    toJSON(generator);//w ww. j  a  v  a  2s .c  o  m
    generator.close();

    return s.toString();
}

From source file:org.wrml.util.AsciiArt.java

public static String express(final Object object) {

    final ObjectWriter objectWriter = new ObjectMapper().writer(new DefaultPrettyPrinter());
    try {//from www  . j  a  va2s  .  co m
        return objectWriter.writeValueAsString(object);
    } catch (final Exception e) {
        LOG.warn(e.getMessage());
    }

    return null;
}

From source file:com.kibana.multitenancy.plugin.acl.DynamicACLFilter.java

private void write(Client esClient, ArmorACL acl) throws JsonProcessingException, InterruptedException {
    if (logger.isDebugEnabled()) {
        logger.debug("Writing ACLs '{}'", mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(acl));
    }//ww w  .  j a  v  a 2  s . c om
    UpdateRequest request = esClient.prepareUpdate(searchGuardIndex, SEARCHGUARD_TYPE, SEARCHGUARD_ID)
            .setDoc(mapper.writeValueAsBytes(acl)).setRefresh(true).request();
    request.putInContext(ES_REQ_ID, ACL_FILTER_ID);
    esClient.update(request).actionGet();
    lock.lock();
    try {
        logger.debug("Waiting up to {} ms. to be notified that SearchGuard has refreshed the ACLs",
                aclSyncDelay);
        syncing.await(aclSyncDelay, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.error("Error while awaiting notification of ACL load by SearchGuard", e);
    } finally {
        lock.unlock();
    }
}

From source file:com.kibana.multitenancy.plugin.acl.DynamicACLFilter.java

private void create(Client esClient, ArmorACL acl) throws JsonProcessingException, InterruptedException {
    if (logger.isDebugEnabled()) {
        logger.debug("Writing ACLs '{}'", mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(acl));
    }//from  ww w .  j  av  a  2  s .  c o  m
    IndexRequest request = esClient.prepareIndex(searchGuardIndex, SEARCHGUARD_TYPE, SEARCHGUARD_ID)
            .setSource(mapper.writeValueAsBytes(acl)).setRefresh(true).request();
    request.putInContext(ES_REQ_ID, ACL_FILTER_ID);
    esClient.index(request).actionGet();
    lock.lock();
    try {
        logger.debug("Waiting up to {} ms. to be notified that SearchGuard has refreshed the ACLs",
                aclSyncDelay);
        syncing.await(aclSyncDelay, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        logger.error("Error while awaiting notification of ACL load by SearchGuard", e);
    } finally {
        lock.unlock();
    }
}

From source file:com.kibana.multitenancy.plugin.acl.DynamicACLFilter.java

private void seedInitialACL(Client esClient) throws Exception {

    ArmorACL acl = new ArmorACL();
    boolean create = false;

    try {// w ww.j  ava 2  s  .  co m
        //This should return nothing initially - if it does, we're done
        acl = loadAcl(esClient);

        if (acl.iterator().hasNext()) {
            if (logger.isDebugEnabled())
                logger.debug("Have already seeded with '{}'",
                        mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(acl));
            seeded = true;
            return;
        }
    }
    //Sushant:ElasticSearch 2.0 Breaking Changes
    //catch (IndexMissingException | DocumentMissingException | NullPointerException e) {
    catch (IndexNotFoundException | DocumentMissingException | NullPointerException e) {
        logger.debug("Caught Exception, ACL has not been seeded yet", e);
        create = true;
    } catch (Exception e) {
        logger.error("Error checking ACL when seeding", e);
        throw e;
    }

    try {
        acl.createInitialACLs();
        if (logger.isDebugEnabled())
            logger.debug("Created initial ACL of '{}'",
                    mapper.writer(new DefaultPrettyPrinter()).writeValueAsString(acl));

        if (create)
            create(esClient, acl);
        else
            write(esClient, acl);
    } catch (Exception e) {
        logger.error("Error seeding initial ACL", e);
        throw e;
    }

    seeded = true;
}

From source file:com.rcv.ResultsWriter.java

private void generateSummaryJson(Map<Integer, Map<String, BigDecimal>> roundTallies, String precinct,
        String outputPath) throws IOException {

    // mapper converts java objects to json
    ObjectMapper mapper = new ObjectMapper();
    // set mapper to order keys alphabetically for more legible output
    mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
    // create a module to contain a serializer for BigDecimal serialization
    SimpleModule module = new SimpleModule();
    module.addSerializer(BigDecimal.class, new ToStringSerializer());
    // attach serializer to mapper
    mapper.registerModule(module);// w  w  w. jav a2s  . c  om

    // jsonWriter writes those object to disk
    ObjectWriter jsonWriter = mapper.writer(new DefaultPrettyPrinter());
    // jsonPath for output json summary
    String jsonPath = outputPath + ".json";
    // log output location
    Logger.log(Level.INFO, "Generating summary JSON file: %s...", jsonPath);
    // outFile is the target file
    File outFile = new File(jsonPath);

    // root outputJson dict will have two entries:
    // results - vote totals, transfers, and candidates elected / eliminated
    // config - global config into
    HashMap<String, Object> outputJson = new HashMap<>();
    // config will contain contest configuration info
    HashMap<String, Object> configData = new HashMap<>();
    // add config header info
    configData.put("contest", config.getContestName());
    configData.put("jurisdiction", config.getContestJurisdiction());
    configData.put("office", config.getContestOffice());
    configData.put("date", config.getContestDate());
    configData.put("threshold", winningThreshold);
    if (precinct != null && !precinct.isEmpty()) {
        configData.put("precinct", precinct);
    }
    // results will be a list of round data objects
    ArrayList<Object> results = new ArrayList<>();
    // for each round create objects for json serialization
    for (int round = 1; round <= numRounds; round++) {
        // container for all json data this round:
        HashMap<String, Object> roundData = new HashMap<>();
        // add round number (this is implied by the ordering but for debugging we are explicit)
        roundData.put("round", round);
        // add actions if this is not a precinct summary
        if (precinct == null || precinct.isEmpty()) {
            // actions is a list of one or more action objects
            ArrayList<Object> actions = new ArrayList<>();
            addActionObjects("elected", roundToWinningCandidates.get(round), round, actions);
            // add any elimination actions
            addActionObjects("eliminated", roundToEliminatedCandidates.get(round), round, actions);
            // add action objects
            roundData.put("tallyResults", actions);
        }
        // add tally object
        roundData.put("tally", updateCandidateNamesInTally(roundTallies.get(round)));
        // add roundData to results list
        results.add(roundData);
    }
    // add config data to root object
    outputJson.put("config", configData);
    // add results to root object
    outputJson.put("results", results);
    // write results to disk
    try {
        jsonWriter.writeValue(outFile, outputJson);
    } catch (IOException exception) {
        Logger.log(Level.SEVERE, "Error writing to JSON file: %s\n%s", jsonPath, exception.toString());
        throw exception;
    }
}