本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeObjectField方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeObjectField方法的具體用法?Java JsonGenerator.writeObjectField怎麽用?Java JsonGenerator.writeObjectField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeObjectField方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(Map<String, Object> fields, JsonGenerator jgen,
SerializerProvider provider) throws IOException,
JsonProcessingException {
jgen.writeStartObject();
for (Entry<String, Object> entry : fields.entrySet()) {
Object objectValue = entry.getValue();
if (objectValue instanceof Date) {
Date date = (Date) objectValue;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("Pacific/Auckland"));
String formattedDate = simpleDateFormat.format(date);
jgen.writeObjectField(entry.getKey().toString(), formattedDate);
} else {
jgen.writeObjectField(entry.getKey().toString(), objectValue);
}
}
jgen.writeEndObject();
}
示例2: write
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Used to write the state of the ClusterNode instance to disk, when we are
* persisting the state of the NodeManager
* @param jsonGenerator The JsonGenerator instance being used to write JSON
* to disk
* @throws IOException
*/
public void write(JsonGenerator jsonGenerator) throws IOException {
jsonGenerator.writeStartObject();
// clusterNodeInfo begins
jsonGenerator.writeFieldName("clusterNodeInfo");
jsonGenerator.writeStartObject();
jsonGenerator.writeStringField("name", clusterNodeInfo.name);
jsonGenerator.writeObjectField("address", clusterNodeInfo.address);
jsonGenerator.writeObjectField("total", clusterNodeInfo.total);
jsonGenerator.writeObjectField("free", clusterNodeInfo.free);
jsonGenerator.writeObjectField("resourceInfos",
clusterNodeInfo.resourceInfos);
jsonGenerator.writeEndObject();
// clusterNodeInfo ends
// grants begins
jsonGenerator.writeFieldName("grants");
jsonGenerator.writeStartObject();
for (Map.Entry<GrantId, ResourceRequestInfo> entry : grants.entrySet()) {
jsonGenerator.writeFieldName(entry.getKey().unique);
jsonGenerator.writeStartObject();
jsonGenerator.writeFieldName("grantId");
entry.getKey().write(jsonGenerator);
jsonGenerator.writeFieldName("grant");
entry.getValue().write(jsonGenerator);
jsonGenerator.writeEndObject();
}
jsonGenerator.writeEndObject();
// grants ends
jsonGenerator.writeEndObject();
// We skip the hostNode and lastHeartbeatTime as they need not be persisted.
// resourceTypeToMaxCpu and resourceTypeToStatsMap can be rebuilt using the
// conf and the grants respectively.
}
示例3: 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();
}
示例4: write
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* This method writes the ResourceRequestInfo instance to disk
* @param jsonGenerator The JsonGenerator instance being used to write the
* JSON to disk
* @throws IOException
*/
public void write(JsonGenerator jsonGenerator) throws IOException {
// We neither need the list of RequestedNodes, nodes, nor excludedHosts,
// because we can reconstruct them from the request object
jsonGenerator.writeStartObject();
jsonGenerator.writeObjectField("request", request);
jsonGenerator.writeEndObject();
}
示例5: writeLinks
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private void writeLinks(final CollectionPage<Object> value, final JsonGenerator jgen) throws IOException {
jgen.writeObjectField("links", getLinks(value));
}
示例6: writeJSON
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
protected void writeJSON(JsonGenerator gen) throws IOException {
for (Map.Entry<String, String> entry : entrySet()) {
gen.writeObjectField(entry.getKey(), entry.getValue());
}
}
示例7: writeJson
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
void writeJson(JsonGenerator gen) throws IOException {
for (Map.Entry<String, String> e : entrySet())
gen.writeObjectField(e.getKey(), e.getValue());
}