本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeNumber方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeNumber方法的具體用法?Java JsonGenerator.writeNumber怎麽用?Java JsonGenerator.writeNumber使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeNumber方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeObject
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private void writeObject(JsonGenerator jg, Object value) throws IOException {
if(value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, item);
}
jg.writeEndArray();
} else if(value instanceof Number) {
Number n = (Number)value;
jg.writeNumber(n.toString());
} else if(value instanceof Boolean) {
Boolean b = (Boolean)value;
jg.writeBoolean(b);
} else if(value instanceof CompositeData) {
CompositeData cds = (CompositeData)value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for(String key: keys) {
writeAttribute(jg, key, cds.get(key));
}
jg.writeEndObject();
} else if(value instanceof TabularData) {
TabularData tds = (TabularData)value;
jg.writeStartArray();
for(Object entry : tds.values()) {
writeObject(jg, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
示例2: persistState
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* This function saves the state of the ClusterManager to disk.
* @return A boolean. True if saving the state succeeded, false otherwise.
*/
@Override
public boolean persistState() {
if (!safeMode) {
LOG.info(
"Cannot persist state because ClusterManager is not in Safe Mode");
return false;
}
try {
JsonGenerator jsonGenerator = CoronaSerializer.createJsonGenerator(conf);
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName("startTime");
jsonGenerator.writeNumber(startTime);
jsonGenerator.writeFieldName("nodeManager");
nodeManager.write(jsonGenerator);
jsonGenerator.writeFieldName("sessionManager");
sessionManager.write(jsonGenerator);
jsonGenerator.writeFieldName("sessionNotifier");
sessionNotifier.write(jsonGenerator);
jsonGenerator.writeEndObject();
jsonGenerator.close();
} catch (IOException e) {
LOG.info("Could not persist the state: ", e);
return false;
}
return true;
}
示例3: writeObject
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private void writeObject(JsonGenerator jg, Object value) throws IOException {
if (value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, item);
}
jg.writeEndArray();
} else if (value instanceof Number) {
Number n = (Number) value;
jg.writeNumber(n.toString());
} else if (value instanceof Boolean) {
Boolean b = (Boolean) value;
jg.writeBoolean(b);
} else if (value instanceof CompositeData) {
CompositeData cds = (CompositeData) value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for (String key : keys) {
writeAttribute(jg, key, cds.get(key));
}
jg.writeEndObject();
} else if (value instanceof TabularData) {
TabularData tds = (TabularData) value;
jg.writeStartArray();
for (Object entry : tds.values()) {
writeObject(jg, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
示例4: 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
示例5: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Short s, JsonGenerator jGen,
SerializerProvider serializer) throws IOException,
JsonProcessingException {
if (s == null) jGen.writeNull();
else jGen.writeNumber(s.shortValue() & 0xffff);
}
開發者ID:vishalshubham,項目名稱:Multipath-Hedera-system-in-Floodlight-controller,代碼行數:8,代碼來源:UShortSerializer.java
示例6: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Date date, JsonGenerator gen, SerializerProvider provider) throws IOException,
JsonProcessingException {
long millis = date.getTime();
Date currentDate = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(currentDate);
int offset = cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET);
gen.writeNumber(millis + offset);
}
示例7: write
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void write(JsonGenerator gen, String value) throws IOException
{
gen.writeNumber(value);
}
示例8: writeObject
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private static void writeObject(final JsonGenerator jg, final boolean description, Object value)
throws IOException {
if(value == null) {
jg.writeNull();
} else {
Class<?> c = value.getClass();
if (c.isArray()) {
jg.writeStartArray();
int len = Array.getLength(value);
for (int j = 0; j < len; j++) {
Object item = Array.get(value, j);
writeObject(jg, description, item);
}
jg.writeEndArray();
} else if(value instanceof Number) {
Number n = (Number)value;
jg.writeNumber(n.toString());
} else if(value instanceof Boolean) {
Boolean b = (Boolean)value;
jg.writeBoolean(b);
} else if(value instanceof CompositeData) {
CompositeData cds = (CompositeData)value;
CompositeType comp = cds.getCompositeType();
Set<String> keys = comp.keySet();
jg.writeStartObject();
for (String key: keys) {
writeAttribute(jg, key, null, cds.get(key));
}
jg.writeEndObject();
} else if(value instanceof TabularData) {
TabularData tds = (TabularData)value;
jg.writeStartArray();
for(Object entry : tds.values()) {
writeObject(jg, description, entry);
}
jg.writeEndArray();
} else {
jg.writeString(value.toString());
}
}
}
示例9: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Date value, JsonGenerator gen, SerializerProvider provider) throws IOException, JsonProcessingException {
String date = String.valueOf(value.getTime());
gen.writeNumber(date);
}
示例10: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Date value, JsonGenerator gen, SerializerProvider arg2) throws IOException, JsonProcessingException {
String formattedDate = String.valueOf(value.getTime());
gen.writeNumber(formattedDate);
}
示例11: writeSimpleProperty
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private static void writeSimpleProperty(JsonGenerator g, String name, long value) throws IOException {
g.writeFieldName(name);
g.writeNumber(value);
}
示例12: writeValue
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/** Called to write value.*/
protected void writeValue(Schema fieldSchema, Object datum, JsonGenerator generator) throws IOException {
try {
switch (fieldSchema.getType()) {
case INT:
generator.writeNumber(((Number) datum).intValue());
break;
case LONG:
generator.writeNumber((Long) datum);
break;
case DOUBLE:
generator.writeNumber((Double) datum);
break;
case BOOLEAN:
generator.writeBoolean((Boolean) datum);
break;
case STRING:
generator.writeString(datum.toString());
break;
case BYTES:
writeBytes(datum, generator);
break;
case NULL:
generator.writeNull();
break;
case RECORD:
writeRecord((RecordSchema) fieldSchema, datum, generator);
break;
case ENUM:
writeEnum((EnumSchema) fieldSchema, (Enum) datum, generator);
break;
case ARRAY:
writeArray((ArraySchema) fieldSchema, (List) datum, generator);
break;
case MAP:
writeMap((MapSchema) fieldSchema, (Map) datum, generator);
break;
case UNION:
writeUnion((UnionSchema) fieldSchema, datum, generator);
break;
default:
error(fieldSchema, datum);
}
} catch (NullPointerException e) {
throw npe(e, " of "+ fieldSchema.getName());
}
}
示例13: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Enum<?> t, JsonGenerator jg, SerializerProvider sp) throws IOException,
JsonGenerationException {
jg.writeNumber(t.ordinal());
}