Example usage for com.fasterxml.jackson.core JsonGenerator writeNumberField

List of usage examples for com.fasterxml.jackson.core JsonGenerator writeNumberField

Introduction

In this page you can find the example usage for com.fasterxml.jackson.core JsonGenerator writeNumberField.

Prototype

public final void writeNumberField(String fieldName, BigDecimal value)
        throws IOException, JsonGenerationException 

Source Link

Document

Convenience method for outputting a field entry ("member") that has the specified numeric value.

Usage

From source file:YDExtDataAssetTypeWriter.java

@Override
protected void write(Integer ext, JsonGenerator gen) throws IOException {
    gen.writeNumberField(Constants.EXTEND_DATA_ASSET_TYPE_FIELD_NAME, ext);
}

From source file:YDExtStandardSchemaIdWriter.java

@Override
protected void write(Integer ext, JsonGenerator gen) throws IOException {
    gen.writeNumberField(Constants.EXTEND_STANDARD_SCHEMA_ID_FIELD_NAME, ext);
}

From source file:com.google.openrtb.json.Test3Writer.java

@Override
protected void write(Integer ext, JsonGenerator gen) throws IOException {
    gen.writeNumberField("test3", ext);
}

From source file:com.netflix.hystrix.serial.SerialHystrixDashboardData.java

private static void writeCommandMetrics(final HystrixCommandMetrics commandMetrics, JsonGenerator json)
        throws IOException {
    HystrixCommandKey key = commandMetrics.getCommandKey();
    HystrixCircuitBreaker circuitBreaker = HystrixCircuitBreaker.Factory.getInstance(key);

    json.writeStartObject();// w  ww.j  ava2 s  .c  o  m
    json.writeStringField("type", "HystrixCommand");
    json.writeStringField("name", key.name());
    json.writeStringField("group", commandMetrics.getCommandGroup().name());
    json.writeNumberField("currentTime", System.currentTimeMillis());

    // circuit breaker
    if (circuitBreaker == null) {
        // circuit breaker is disabled and thus never open
        json.writeBooleanField("isCircuitBreakerOpen", false);
    } else {
        json.writeBooleanField("isCircuitBreakerOpen", circuitBreaker.isOpen());
    }
    HystrixCommandMetrics.HealthCounts healthCounts = commandMetrics.getHealthCounts();
    json.writeNumberField("errorPercentage", healthCounts.getErrorPercentage());
    json.writeNumberField("errorCount", healthCounts.getErrorCount());
    json.writeNumberField("requestCount", healthCounts.getTotalRequests());

    // rolling counters
    safelyWriteNumberField(json, "rollingCountBadRequests", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.BAD_REQUEST);
        }
    });
    safelyWriteNumberField(json, "rollingCountCollapsedRequests", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.COLLAPSED);
        }
    });
    safelyWriteNumberField(json, "rollingCountEmit", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.EMIT);
        }
    });
    safelyWriteNumberField(json, "rollingCountExceptionsThrown", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.EXCEPTION_THROWN);
        }
    });
    safelyWriteNumberField(json, "rollingCountFailure", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FAILURE);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackEmit", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_EMIT);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackFailure", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_FAILURE);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackMissing", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_MISSING);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackRejection", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_REJECTION);
        }
    });
    safelyWriteNumberField(json, "rollingCountFallbackSuccess", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.FALLBACK_SUCCESS);
        }
    });
    safelyWriteNumberField(json, "rollingCountResponsesFromCache", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.RESPONSE_FROM_CACHE);
        }
    });
    safelyWriteNumberField(json, "rollingCountSemaphoreRejected", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SEMAPHORE_REJECTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountShortCircuited", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SHORT_CIRCUITED);
        }
    });
    safelyWriteNumberField(json, "rollingCountSuccess", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.SUCCESS);
        }
    });
    safelyWriteNumberField(json, "rollingCountThreadPoolRejected", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.THREAD_POOL_REJECTED);
        }
    });
    safelyWriteNumberField(json, "rollingCountTimeout", new Func0<Long>() {
        @Override
        public Long call() {
            return commandMetrics.getRollingCount(HystrixEventType.TIMEOUT);
        }
    });

    json.writeNumberField("currentConcurrentExecutionCount",
            commandMetrics.getCurrentConcurrentExecutionCount());
    json.writeNumberField("rollingMaxConcurrentExecutionCount",
            commandMetrics.getRollingMaxConcurrentExecutions());

    // latency percentiles
    json.writeNumberField("latencyExecute_mean", commandMetrics.getExecutionTimeMean());
    json.writeObjectFieldStart("latencyExecute");
    json.writeNumberField("0", commandMetrics.getExecutionTimePercentile(0));
    json.writeNumberField("25", commandMetrics.getExecutionTimePercentile(25));
    json.writeNumberField("50", commandMetrics.getExecutionTimePercentile(50));
    json.writeNumberField("75", commandMetrics.getExecutionTimePercentile(75));
    json.writeNumberField("90", commandMetrics.getExecutionTimePercentile(90));
    json.writeNumberField("95", commandMetrics.getExecutionTimePercentile(95));
    json.writeNumberField("99", commandMetrics.getExecutionTimePercentile(99));
    json.writeNumberField("99.5", commandMetrics.getExecutionTimePercentile(99.5));
    json.writeNumberField("100", commandMetrics.getExecutionTimePercentile(100));
    json.writeEndObject();
    //
    json.writeNumberField("latencyTotal_mean", commandMetrics.getTotalTimeMean());
    json.writeObjectFieldStart("latencyTotal");
    json.writeNumberField("0", commandMetrics.getTotalTimePercentile(0));
    json.writeNumberField("25", commandMetrics.getTotalTimePercentile(25));
    json.writeNumberField("50", commandMetrics.getTotalTimePercentile(50));
    json.writeNumberField("75", commandMetrics.getTotalTimePercentile(75));
    json.writeNumberField("90", commandMetrics.getTotalTimePercentile(90));
    json.writeNumberField("95", commandMetrics.getTotalTimePercentile(95));
    json.writeNumberField("99", commandMetrics.getTotalTimePercentile(99));
    json.writeNumberField("99.5", commandMetrics.getTotalTimePercentile(99.5));
    json.writeNumberField("100", commandMetrics.getTotalTimePercentile(100));
    json.writeEndObject();

    // property values for reporting what is actually seen by the command rather than what was set somewhere
    HystrixCommandProperties commandProperties = commandMetrics.getProperties();

    json.writeNumberField("propertyValue_circuitBreakerRequestVolumeThreshold",
            commandProperties.circuitBreakerRequestVolumeThreshold().get());
    json.writeNumberField("propertyValue_circuitBreakerSleepWindowInMilliseconds",
            commandProperties.circuitBreakerSleepWindowInMilliseconds().get());
    json.writeNumberField("propertyValue_circuitBreakerErrorThresholdPercentage",
            commandProperties.circuitBreakerErrorThresholdPercentage().get());
    json.writeBooleanField("propertyValue_circuitBreakerForceOpen",
            commandProperties.circuitBreakerForceOpen().get());
    json.writeBooleanField("propertyValue_circuitBreakerForceClosed",
            commandProperties.circuitBreakerForceClosed().get());
    json.writeBooleanField("propertyValue_circuitBreakerEnabled",
            commandProperties.circuitBreakerEnabled().get());

    json.writeStringField("propertyValue_executionIsolationStrategy",
            commandProperties.executionIsolationStrategy().get().name());
    json.writeNumberField("propertyValue_executionIsolationThreadTimeoutInMilliseconds",
            commandProperties.executionTimeoutInMilliseconds().get());
    json.writeNumberField("propertyValue_executionTimeoutInMilliseconds",
            commandProperties.executionTimeoutInMilliseconds().get());
    json.writeBooleanField("propertyValue_executionIsolationThreadInterruptOnTimeout",
            commandProperties.executionIsolationThreadInterruptOnTimeout().get());
    json.writeStringField("propertyValue_executionIsolationThreadPoolKeyOverride",
            commandProperties.executionIsolationThreadPoolKeyOverride().get());
    json.writeNumberField("propertyValue_executionIsolationSemaphoreMaxConcurrentRequests",
            commandProperties.executionIsolationSemaphoreMaxConcurrentRequests().get());
    json.writeNumberField("propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests",
            commandProperties.fallbackIsolationSemaphoreMaxConcurrentRequests().get());

    /*
     * The following are commented out as these rarely change and are verbose for streaming for something people don't change.
     * We could perhaps allow a property or request argument to include these.
     */

    //                    json.put("propertyValue_metricsRollingPercentileEnabled", commandProperties.metricsRollingPercentileEnabled().get());
    //                    json.put("propertyValue_metricsRollingPercentileBucketSize", commandProperties.metricsRollingPercentileBucketSize().get());
    //                    json.put("propertyValue_metricsRollingPercentileWindow", commandProperties.metricsRollingPercentileWindowInMilliseconds().get());
    //                    json.put("propertyValue_metricsRollingPercentileWindowBuckets", commandProperties.metricsRollingPercentileWindowBuckets().get());
    //                    json.put("propertyValue_metricsRollingStatisticalWindowBuckets", commandProperties.metricsRollingStatisticalWindowBuckets().get());
    json.writeNumberField("propertyValue_metricsRollingStatisticalWindowInMilliseconds",
            commandProperties.metricsRollingStatisticalWindowInMilliseconds().get());

    json.writeBooleanField("propertyValue_requestCacheEnabled", commandProperties.requestCacheEnabled().get());
    json.writeBooleanField("propertyValue_requestLogEnabled", commandProperties.requestLogEnabled().get());

    json.writeNumberField("reportingHosts", 1); // this will get summed across all instances in a cluster
    json.writeStringField("threadPool", commandMetrics.getThreadPoolKey().name());

    json.writeEndObject();
}

From source file:org.webpda.server.core.servermessage.PingMessage.java

@Override
public String createJson() throws JsonProcessingException {
    try {/*from  ww w .  j a v  a 2  s  .c o m*/
        JsonGenerator jg = createJsonGenerator();
        jg.writeNumberField("Count", count);

        jg.writeEndObject();
        jg.close();
        ByteArrayOutputStream outputStream = (ByteArrayOutputStream) jg.getOutputTarget();
        String s = outputStream.toString(Constants.CHARSET);
        outputStream.close();
        return s;
    } catch (Exception e) {
        LoggerUtil.getLogger().log(Level.SEVERE, "Failed to create json.", e);
    }

    return null;
}

From source file:org.springframework.social.wunderlist.api.impl.json.UpdateListDataSerializer.java

private void write(JsonGenerator generator, UpdateListData data) throws IOException {
    generator.writeNumberField("revision", data.getRevision());
    if (data.isPublished() != null) {
        generator.writeBooleanField("public", data.isPublished());
    }//from www. j  a v  a 2  s . c  o  m
    if (data.getTitle() != null) {
        generator.writeStringField("title", data.getTitle());
    }
}

From source file:org.springframework.social.wunderlist.api.impl.json.CreateTaskDataSerializer.java

private void write(JsonGenerator generator, CreateTaskData data) throws IOException {
    generator.writeNumberField("list_id", data.getListId());
    generator.writeStringField("title", data.getTitle());
    generator.writeBooleanField("completed", data.isCompleted());
    generator.writeBooleanField("starred", data.isStarred());
    if (data.getAssigneeId() != null) {
        generator.writeNumberField("assignee_id", data.getAssigneeId());
    }/*from  w ww  . j  a va 2  s .c  om*/
    if (data.getRecurrence() != null) {
        generator.writeStringField("recurrence_type", data.getRecurrence().getType().value());
        generator.writeNumberField("recurrence_count", data.getRecurrence().getCount());
    }
    if (data.getDueDate() != null) {
        generator.writeStringField("due_date", new SimpleDateFormat("yyyy-MM-dd").format(data.getDueDate()));
    }
}

From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.api.ScaleOutController.java

/**
 * Allows to scale out the Cassandra cluster by increasing the number of nodes.
 * Requires the query parameter {@code nodes} defining the desired number of total nodes.
 * Must be submitted using HTTP method {@code POST}.
 *//*from   w ww .j a  v a  2  s . c o m*/
@POST
@Path("/nodes")
public Response updateNodeCount(@QueryParam("nodeCount") final int nodeCount) {
    try {
        final int newCount = cluster.updateNodeCount(nodeCount);
        return JaxRsUtils.buildStreamingResponse(factory, new StreamingJsonResponse() {
            @Override
            public void write(final JsonGenerator json) throws IOException {
                json.writeNumberField("newNodeCount", newCount);
            }
        });
    } catch (IllegalArgumentException e) {
        return Response.status(Response.Status.BAD_REQUEST).type("application/json")
                .entity(String.format("{\"message\":\"%s\"}", e.getMessage())).build();
    }
}

From source file:com.ntsync.shared.RequestGenerator.java

private static byte[] createHeader(SyncAnchor syncAnchor, String pkgVersion, String clientId,
        String pwdSaltHexStr, Map<Long, String> newIdMap, boolean syncOnlyGroup, Restrictions restr,
        boolean explizitPhotoSave) throws HeaderCreateException {

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {/*from  w  ww .  j  a v a2s. c  o  m*/
        JsonGenerator g = getJsonFactory().createGenerator(out);

        g.writeStartObject();

        g.writeObjectFieldStart(CLIENT_FIELD_NAME);

        g.writeObjectFieldStart(PARAM_SYNC_ANCHOR);
        for (Byte contType : syncAnchor.containers()) {
            long anchor = syncAnchor.getAnchor(contType);
            if (anchor > 0) {
                String type = String.valueOf((char) contType.byteValue());
                g.writeNumberField(type, anchor);
            }
        }
        g.writeEndObject();

        if (syncOnlyGroup) {
            LOG.info("Sync only ContactGroups");
            g.writeBooleanField(PARAM_SYNCONLYGROUP, true);
        }

        g.writeStringField(FIELD_SOFTWARE, "Android|" + pkgVersion);

        // Set ClientId
        if (clientId != null) {
            g.writeStringField(PARAM_CLIENTID, clientId);
        }

        if (restr != null) {
            g.writeBooleanField(PARAM_IS_PHOTO_SYNC_ENABLED, restr.isPhotoSyncSupported());
        }

        if (explizitPhotoSave) {
            g.writeBooleanField(PARAM_FORCE_PHOTO_SAVE, true);
        }

        // Set PwdSalt
        if (pwdSaltHexStr != null) {
            g.writeStringField(FIELD_PWDSALT, pwdSaltHexStr);
        }

        if (newIdMap != null && !newIdMap.isEmpty()) {
            g.writeObjectFieldStart(TAG_CONTACTIDS);
            for (Map.Entry<Long, String> idRow : newIdMap.entrySet()) {
                String serverId = idRow.getValue();
                if (serverId != null && serverId.length() > 0) {
                    g.writeStringField(String.valueOf(idRow.getKey()), serverId);
                }
            }
            g.writeEndObject();
        }
        g.writeEndObject();
        g.writeEndObject();
        g.close();
    } catch (IOException ex) {
        throw new HeaderCreateException(ex);
    }

    return out.toByteArray();
}

From source file:org.springframework.social.wunderlist.api.impl.json.UpdateTaskDataSerializer.java

private void write(JsonGenerator generator, UpdateTaskData data) throws IOException {
    generator.writeNumberField("revision", data.getRevision());
    if (data.getTitle() != null) {
        generator.writeStringField("title", data.getTitle());
    }//  w w  w.ja  va  2  s .com
    if (data.getAssigneeId() != null) {
        generator.writeNumberField("assignee_id", data.getAssigneeId());
    }
    if (data.isStarred() != null) {
        generator.writeBooleanField("starred", data.isStarred());
    }
    if (data.isCompleted() != null) {
        generator.writeBooleanField("completed", data.isCompleted());
    }
    if (data.getRecurrence() != null) {
        generator.writeStringField("recurrence_type", data.getRecurrence().getType().value());
        generator.writeNumberField("recurrence_count", data.getRecurrence().getCount());
    }
    if (data.getDueDate() != null) {
        generator.writeStringField("due_date", new SimpleDateFormat("yyyy-MM-dd").format(data.getDueDate()));
    }
}