本文整理汇总了Java中org.codehaus.jackson.JsonGenerator.writeNumberField方法的典型用法代码示例。如果您正苦于以下问题:Java JsonGenerator.writeNumberField方法的具体用法?Java JsonGenerator.writeNumberField怎么用?Java JsonGenerator.writeNumberField使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeNumberField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Performs the serialization of a OFFeaturesReply object
*/
@Override
public void serialize(OFFeaturesReply reply, JsonGenerator jGen, SerializerProvider serializer) throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeNumberField("actions", reply.getActions());
jGen.writeNumberField("buffers", reply.getBuffers());
jGen.writeNumberField("capabilities", reply.getCapabilities());
jGen.writeStringField("datapathId", HexString.toHexString(reply.getDatapathId()));
jGen.writeNumberField("length", reply.getLength());
serializer.defaultSerializeField("ports", reply.getPorts(), jGen);
jGen.writeNumberField("tables", reply.getTables());
jGen.writeStringField("type", reply.getType().toString());
jGen.writeNumberField("version", reply.getVersion());
jGen.writeNumberField("xid", reply.getXid());
jGen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:19,代码来源:OFFeaturesReplyJSONSerializer.java
示例2: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Performs the serialization of a OneComponentTime object
*/
@Override
public void serialize(CumulativeTimeBucket ctb,
JsonGenerator jGen,
SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.writeStartObject();
Timestamp ts = new Timestamp(ctb.getStartTimeNs()/1000000);
jGen.writeStringField("start-time", ts.toString());
jGen.writeStringField("current-time",
new Timestamp(System.currentTimeMillis()).toString());
jGen.writeNumberField("total-packets", ctb.getTotalPktCnt());
jGen.writeNumberField("average", ctb.getAverageProcTimeNs());
jGen.writeNumberField("min", ctb.getMinTotalProcTimeNs());
jGen.writeNumberField("max", ctb.getMaxTotalProcTimeNs());
jGen.writeNumberField("std-dev", ctb.getTotalSigmaProcTimeNs());
jGen.writeArrayFieldStart("modules");
for (OneComponentTime oct : ctb.getModules()) {
serializer.defaultSerializeValue(oct, jGen);
}
jGen.writeEndArray();
jGen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:26,代码来源:CumulativeTimeBucketJSONSerializer.java
示例3: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Performs the serialization of a EventHistory.BaseInfo object
*/
@Override
public void serialize(EventHistoryBaseInfo base_info, JsonGenerator jGen,
SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeNumberField("Idx", base_info.getIdx());
Timestamp ts = new Timestamp(base_info.getTime_ms());
String tsStr = ts.toString();
while (tsStr.length() < 23) {
tsStr = tsStr.concat("0");
}
jGen.writeStringField("Time", tsStr);
jGen.writeStringField("State", base_info.getState().name());
String acStr = base_info.getAction().name().toLowerCase();
// Capitalize the first letter
acStr = acStr.substring(0,1).toUpperCase().concat(acStr.substring(1));
jGen.writeStringField("Action", acStr);
jGen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:23,代码来源:EventHistoryBaseInfoJSONSerializer.java
示例4: toJson
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Build a JSON entry from the parameters. This is public for testing.
*
* @param writer destination
* @param loggerName logger name
* @param timeStamp time_t value
* @param level level string
* @param threadName name of the thread
* @param message rendered message
* @param ti nullable thrown information
* @return the writer
* @throws IOException on any problem
*/
public Writer toJson(final Writer writer,
final String loggerName,
final long timeStamp,
final String level,
final String threadName,
final String message,
final ThrowableInformation ti) throws IOException {
JsonGenerator json = factory.createJsonGenerator(writer);
json.writeStartObject();
json.writeStringField(NAME, loggerName);
json.writeNumberField(TIME, timeStamp);
Date date = new Date(timeStamp);
json.writeStringField(DATE, dateFormat.format(date));
json.writeStringField(LEVEL, level);
json.writeStringField(THREAD, threadName);
json.writeStringField(MESSAGE, message);
if (ti != null) {
//there is some throwable info, but if the log event has been sent over the wire,
//there may not be a throwable inside it, just a summary.
Throwable thrown = ti.getThrowable();
String eclass = (thrown != null) ?
thrown.getClass().getName()
: "";
json.writeStringField(EXCEPTION_CLASS, eclass);
String[] stackTrace = ti.getThrowableStrRep();
json.writeArrayFieldStart(STACK);
for (String row : stackTrace) {
json.writeString(row);
}
json.writeEndArray();
}
json.writeEndObject();
json.flush();
json.close();
return writer;
}
示例5: write
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Used to write the state of the SessionNotificationCtx instance to disk,
* when we are persisting the state of the ClusterManager
* @param jsonGenerator The JsonGenerator instance being used to write JSON
* to disk
* @throws IOException
*/
public void write(JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("handle", handle);
jsonGenerator.writeStringField("host", host);
jsonGenerator.writeNumberField("port", port);
jsonGenerator.writeNumberField("numPendingCalls", pendingCalls.size());
jsonGenerator.writeFieldName("pendingCalls");
jsonGenerator.writeStartArray();
for (TBase call : pendingCalls) {
jsonGenerator.writeStartObject();
// TBase is an abstract class. While reading back, we want to know
// what kind of object we actually wrote. Jackson does provide two methods
// to do it automatically, but one of them adds types at a lot of places
// where we don't need it, and hence our parsing would be required to be
// changed. The other required adding an annotation to the TBase class,
// which we can't do, since it is auto-generated by Thrift.
String callType = call.getClass().getName();
jsonGenerator.writeStringField("callType", callType);
jsonGenerator.writeObjectField("call", call);
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
示例6: write
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Used to write the state of the SessionNotifier instance to disk, when we
* are persisting the state of the ClusterManager
*
* @param jsonGenerator The JsonGenerator instance being used to write JSON
* to disk
* @throws IOException
*/
public void write(JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
int totalSessionsToCtx = 0, totalDeletedSessions = 0;
for (int i = 0; i < numNotifierThreads; i++) {
totalSessionsToCtx += notifierThreads[i].sessionsToCtx.size();
totalDeletedSessions += notifierThreads[i].deletedSessions.size();
}
jsonGenerator.writeNumberField("totalSessionsToCtx",
totalSessionsToCtx);
jsonGenerator.writeFieldName("sessionsToCtx");
jsonGenerator.writeStartObject();
for (int i = 0; i < numNotifierThreads; i++) {
for (ConcurrentMap.Entry<String, SessionNotificationCtx> entry :
notifierThreads[i].sessionsToCtx.entrySet()) {
jsonGenerator.writeFieldName(entry.getKey());
entry.getValue().write(jsonGenerator);
}
}
jsonGenerator.writeEndObject();
jsonGenerator.writeNumberField("totalDeletedSessions",
totalDeletedSessions);
jsonGenerator.writeFieldName("deletedSessions");
jsonGenerator.writeStartArray();
for (int i = 0; i < numNotifierThreads; i++) {
for (String deletedSessionHandle :
notifierThreads[i].deletedSessions.keySet()) {
jsonGenerator.writeString(deletedSessionHandle);
}
}
jsonGenerator.writeEndArray();
jsonGenerator.writeEndObject();
}
示例7: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Performs the serialization of a OFMatch object
*/
@Override
public void serialize(OFMatch match, JsonGenerator jGen,
SerializerProvider serializer)
throws IOException, JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("dataLayerDestination",
HexString.toHexString(match.getDataLayerDestination()));
jGen.writeStringField("dataLayerSource",
HexString.toHexString(match.getDataLayerSource()));
String dataType = Integer.toHexString(match.getDataLayerType());
while (dataType.length() < 4) {
dataType = "0".concat(dataType);
}
jGen.writeStringField("dataLayerType", "0x" + dataType);
jGen.writeNumberField("dataLayerVirtualLan",
match.getDataLayerVirtualLan());
jGen.writeNumberField("dataLayerVirtualLanPriorityCodePoint",
match.getDataLayerVirtualLanPriorityCodePoint());
jGen.writeNumberField("inputPort", match.getInputPort());
jGen.writeStringField("networkDestination",
intToIp(match.getNetworkDestination()));
jGen.writeNumberField("networkDestinationMaskLen",
match.getNetworkDestinationMaskLen());
jGen.writeNumberField("networkProtocol", match.getNetworkProtocol());
jGen.writeStringField("networkSource",
intToIp(match.getNetworkSource()));
jGen.writeNumberField("networkSourceMaskLen",
match.getNetworkSourceMaskLen());
jGen.writeNumberField("networkTypeOfService",
match.getNetworkTypeOfService());
jGen.writeNumberField("transportDestination",
match.getTransportDestination());
jGen.writeNumberField("transportSource",
match.getTransportSource());
jGen.writeNumberField("wildcards", match.getWildcards());
jGen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:41,代码来源:OFMatchJSONSerializer.java
示例8: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Device device, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
jGen.writeStartObject();
jGen.writeStringField("entityClass", device.getEntityClass().getName());
jGen.writeArrayFieldStart("mac");
jGen.writeString(HexString.toHexString(device.getMACAddress(), 6));
jGen.writeEndArray();
jGen.writeArrayFieldStart("ipv4");
for (Integer ip : device.getIPv4Addresses())
jGen.writeString(IPv4.fromIPv4Address(ip));
jGen.writeEndArray();
jGen.writeArrayFieldStart("vlan");
for (Short vlan : device.getVlanId())
if (vlan >= 0)
jGen.writeNumber(vlan);
jGen.writeEndArray();
jGen.writeArrayFieldStart("attachmentPoint");
for (SwitchPort ap : device.getAttachmentPoints(true)) {
serializer.defaultSerializeValue(ap, jGen);
}
jGen.writeEndArray();
jGen.writeNumberField("lastSeen", device.getLastSeen().getTime());
jGen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:33,代码来源:DeviceSerializer.java
示例9: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(LinkWithType lwt, JsonGenerator jgen, SerializerProvider arg2)
throws IOException, JsonProcessingException {
// You ****MUST*** use lwt for the fields as it's actually a different object.
jgen.writeStartObject();
jgen.writeStringField("src-switch", HexString.toHexString(lwt.srcSwDpid));
jgen.writeNumberField("src-port", lwt.srcPort);
jgen.writeNumberField("src-port-state", lwt.srcPortState);
jgen.writeStringField("dst-switch", HexString.toHexString(lwt.dstSwDpid));
jgen.writeNumberField("dst-port", lwt.dstPort);
jgen.writeNumberField("dst-port-state", lwt.dstPortState);
jgen.writeStringField("type", lwt.type.toString());
jgen.writeEndObject();
}
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:15,代码来源:LinkWithType.java
示例10: createAggregatedResponse
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
public static Response createAggregatedResponse(final BasicStatusHolder status, final String performedOn) {
StreamingOutput streamingOutput = new StreamingOutput() {
@Override
public void write(OutputStream outputStream) throws IOException, WebApplicationException {
JsonGenerator jsonGenerator = JacksonFactory.createJsonGenerator(outputStream);
jsonGenerator.writeStartObject();
if (status.hasErrors()) {
jsonGenerator.writeArrayFieldStart("errors");
for (StatusEntry error : status.getErrors()) {
jsonGenerator.writeStartObject();
jsonGenerator.writeNumberField("status", error.getStatusCode());
jsonGenerator.writeStringField("message", error.getMessage());
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndArray();
} else {
String msg = "Pushing " + performedOn + " to Bintray finished" + (status.hasWarnings() ?
" with warnings, view the log for details" : " to Bintray finished successfully.");
jsonGenerator.writeStringField("message", msg);
}
jsonGenerator.writeEndObject();
jsonGenerator.close();
}
};
int statusCode = HttpStatus.SC_OK;
if (status.hasErrors()) {
statusCode = status.getErrors().size() > 1 ? HttpStatus.SC_CONFLICT : status.getStatusCode();
}
return Response.status(statusCode).entity(streamingOutput).type(MediaType.APPLICATION_JSON_TYPE).build();
}
示例11: doGet
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("application/json; charset=UTF-8");
StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
getServletContext());
StartupProgressView view = prog.createView();
JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
try {
json.writeStartObject();
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
json.writeArrayFieldStart(PHASES);
for (Phase phase: view.getPhases()) {
json.writeStartObject();
json.writeStringField(NAME, phase.getName());
json.writeStringField(DESC, phase.getDescription());
json.writeStringField(STATUS, view.getStatus(phase).toString());
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase));
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase));
writeStringFieldIfNotNull(json, FILE, view.getFile(phase));
writeNumberFieldIfDefined(json, SIZE, view.getSize(phase));
json.writeArrayFieldStart(STEPS);
for (Step step: view.getSteps(phase)) {
json.writeStartObject();
StepType type = step.getType();
if (type != null) {
json.writeStringField(NAME, type.getName());
json.writeStringField(DESC, type.getDescription());
}
json.writeNumberField(COUNT, view.getCount(phase, step));
writeStringFieldIfNotNull(json, FILE, step.getFile());
writeNumberFieldIfDefined(json, SIZE, step.getSize());
json.writeNumberField(TOTAL, view.getTotal(phase, step));
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase,
step));
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase, step));
json.writeEndObject();
}
json.writeEndArray();
json.writeEndObject();
}
json.writeEndArray();
json.writeEndObject();
} finally {
IOUtils.cleanup(LOG, json);
}
}
示例12: encodeColumn
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
/**
* Encode the column properly in Json.
*
* @param col the column data we are encoding
* @param jdbcType the column type
* @param jg handle to the JsonGenerator
* @throws IOException if a JSON encodng error occurs
*/
private void encodeColumn(DownstreamColumnData col, int jdbcType, JsonGenerator jg) throws IOException {
if (col.checkForNULL()) {
jg.writeNullField(col.getBDName());
} else {
switch (jdbcType) {
case java.sql.Types.BOOLEAN:
case java.sql.Types.BIT:
jg.writeBooleanField(col.getBDName(), col.asBoolean());
break;
case java.sql.Types.SMALLINT:
case java.sql.Types.TINYINT:
case java.sql.Types.INTEGER:
jg.writeNumberField(col.getBDName(), col.asInteger());
break;
case java.sql.Types.BIGINT:
jg.writeNumberField(col.getBDName(), col.asLong());
break;
case java.sql.Types.CHAR:
case java.sql.Types.VARCHAR:
case java.sql.Types.LONGVARCHAR:
case java.sql.Types.CLOB:
jg.writeStringField(col.getBDName(), col.asString());
break;
case java.sql.Types.NCHAR:
case java.sql.Types.NVARCHAR:
case java.sql.Types.LONGNVARCHAR:
case java.sql.Types.NCLOB:
jg.writeStringField(col.getBDName(), col.asString());
break;
case java.sql.Types.BLOB:
case java.sql.Types.BINARY:
case java.sql.Types.LONGVARBINARY:
case java.sql.Types.VARBINARY:
jg.writeBinaryField(col.getBDName(), col.asBytes());
break;
case java.sql.Types.REAL: // JDBC says 7 digits of mantisa
jg.writeNumberField(col.getBDName(), col.asFloat());
break;
case java.sql.Types.FLOAT: // JDBC says 15 digits of mantisa
case java.sql.Types.DOUBLE:
jg.writeNumberField(col.getBDName(), col.asDouble());
break;
case java.sql.Types.NUMERIC:
case java.sql.Types.DECIMAL:
jg.writeNumberField(col.getBDName(), col.asBigDecimal());
break;
case java.sql.Types.DATE:
case java.sql.Types.TIME:
case java.sql.Types.TIMESTAMP:
jg.writeStringField(col.getBDName(), col.asString());
break;
case java.sql.Types.DATALINK:
case java.sql.Types.DISTINCT:
case java.sql.Types.JAVA_OBJECT:
case java.sql.Types.NULL:
case java.sql.Types.ROWID:
case java.sql.Types.SQLXML:
case java.sql.Types.STRUCT:
case java.sql.Types.ARRAY:
case java.sql.Types.OTHER:
case java.sql.Types.REF:
default:
jg.writeStringField(col.getBDName(), "unsupported");
break;
}
}
}
示例13: doGet
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("application/json; charset=UTF-8");
StartupProgress prog = NameNodeHttpServer.getStartupProgressFromContext(
getServletContext());
StartupProgressView view = prog.createView();
JsonGenerator json = new JsonFactory().createJsonGenerator(resp.getWriter());
try {
json.writeStartObject();
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime());
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete());
json.writeArrayFieldStart(PHASES);
for (Phase phase: view.getPhases()) {
json.writeStartObject();
json.writeStringField(NAME, phase.getName());
json.writeStringField(STATUS, view.getStatus(phase).toString());
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase));
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase));
writeStringFieldIfNotNull(json, FILE, view.getFile(phase));
writeNumberFieldIfDefined(json, SIZE, view.getSize(phase));
json.writeArrayFieldStart(STEPS);
for (Step step: view.getSteps(phase)) {
json.writeStartObject();
StepType type = step.getType();
String name = type != null ? type.getName() : null;
writeStringFieldIfNotNull(json, NAME, name);
json.writeNumberField(COUNT, view.getCount(phase, step));
writeStringFieldIfNotNull(json, FILE, step.getFile());
writeNumberFieldIfDefined(json, SIZE, step.getSize());
json.writeNumberField(TOTAL, view.getTotal(phase, step));
json.writeNumberField(PERCENT_COMPLETE, view.getPercentComplete(phase,
step));
json.writeNumberField(ELAPSED_TIME, view.getElapsedTime(phase, step));
json.writeEndObject();
}
json.writeEndArray();
json.writeEndObject();
}
json.writeEndArray();
json.writeEndObject();
} finally {
IOUtils.cleanup(LOG, json);
}
}
示例14: writeTotalSize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
private void writeTotalSize(final CollectionPage<Object> value, final JsonGenerator jgen) throws IOException {
if (null != value.getTotalSize()) {
jgen.writeNumberField("total", value.getTotalSize());
}
}
示例15: serialize
import org.codehaus.jackson.JsonGenerator; //导入方法依赖的package包/类
@Override
public void serialize(Offering value, JsonGenerator jgen,
SerializerProvider provider) throws IOException, JsonProcessingException {
jgen.writeStartObject();
jgen.writeStringField("name", value.getName());
jgen.writeStringField("description", value.getName());
UnitPriceSpecification price = value.getUnitPriceSpecification();
jgen.writeStringField("priceCurrency", price.getHasCurrency());
jgen.writeNumberField("lowPrice", price.getHasMinCurrencyValue());
jgen.writeNumberField("highPrice", price.getHasMaxCurrencyValue());
jgen.writeEndObject();
}