本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeFieldName方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeFieldName方法的具體用法?Java JsonGenerator.writeFieldName怎麽用?Java JsonGenerator.writeFieldName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.codehaus.jackson.JsonGenerator
的用法示例。
在下文中一共展示了JsonGenerator.writeFieldName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: next
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public String next()
{
CSVRecord record = inner.next();
StringWriter json = new StringWriter();
try {
JsonGenerator gen = jsonFactory.createJsonGenerator(json);
gen.writeStartObject();
for (CSVHeaderMap.Entry entry : headerMap.entries()) {
String name = entry.getName();
String value = record.get(entry.getIndex());
gen.writeFieldName(name);
entry.getWriter().write(gen, value);
}
gen.writeEndObject();
gen.close();
}
catch (IOException e) {
throw new RuntimeException(e);
}
return json.toString();
}
示例2: writeAttribute
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private static void writeAttribute(JsonGenerator jg, String attName, final String descriptionStr,
Object value)
throws IOException {
boolean description = false;
if (descriptionStr != null && descriptionStr.length() > 0 && !attName.equals(descriptionStr)) {
description = true;
jg.writeFieldName(attName);
jg.writeStartObject();
jg.writeFieldName("description");
jg.writeString(descriptionStr);
jg.writeFieldName("value");
writeObject(jg, description, value);
jg.writeEndObject();
} else {
jg.writeFieldName(attName);
writeObject(jg, description, value);
}
}
示例3: setBeforeInfo
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Populate transaction meta data into the record if requested.
*
* @param jg the handle to the JsonGenerator
* @param op the database operation we are processing.
* @throws IOException if a JSON encoding error occurs
*/
private void setBeforeInfo(JsonGenerator jg, DownstreamOperation op) throws IOException {
LOG.debug("setBeforeInfo()");
jg.writeFieldName("priorValues");
jg.writeStartObject();
// loop through operatons with calls to appropriate jg.write() methods
for (DownstreamColumnData col : op.getBefores()) {
if (textOnly == true) {
jg.writeStringField(col.getBDName(), col.asString());
} else {
// Encode the data appropriately: handle numbers as numbers, etc.
int jdbcType;
jdbcType = op.getTableMeta().getColumn(col.getOrigName()).getJdbcType();
encodeColumn(col, jdbcType, jg);
}
}
jg.writeEndObject();
}
示例4: toString
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Render this as <a href="http://json.org/">JSON</a>.
*
* @param pretty if true, pretty-print JSON.
*/
public String toString(boolean pretty) {
try {
StringWriter writer = new StringWriter();
JsonGenerator gen = FACTORY.createJsonGenerator(writer);
if (pretty) gen.useDefaultPrettyPrinter();
if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
gen.writeStartObject();
gen.writeFieldName("type");
}
writeJson(gen, new SchemaNames(), null);
if (this instanceof PrimitiveSchema || this instanceof UnionSchema) {
gen.writeEndObject();
}
gen.flush();
return writer.toString();
} catch (IOException e) {
throw new BaijiRuntimeException(e);
}
}
示例5: writeJsonFields
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names) throws IOException {
schemaName.writeJSON(gen);
if (StringUtils.hasLength(doc)) {
gen.writeFieldName("doc");
gen.writeString(doc);
}
if (aliases != null) {
gen.writeFieldName("aliases");
gen.writeStartArray();
for (String a : aliases) {
gen.writeString(a);
}
gen.writeEndArray();
}
}
示例6: dumpConfiguration
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
* Writes out all the parameters and their properties (final and resource) to
* the given {@link Writer}
* The format of the output would be
* { "properties" : [ {key1,value1,key1.isFinal,key1.resource}, {key2,value2,
* key2.isFinal,key2.resource}... ] }
* It does not output the parameters of the configuration object which is
* loaded from an input stream.
* @param out the Writer to write to
* @throws IOException
*/
public static void dumpConfiguration(Configuration config,
Writer out) throws IOException {
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("properties");
dumpGenerator.writeStartArray();
dumpGenerator.flush();
synchronized (config) {
for (Map.Entry<Object,Object> item: config.getProps().entrySet()) {
dumpGenerator.writeStartObject();
dumpGenerator.writeStringField("key", (String) item.getKey());
dumpGenerator.writeStringField("value",
config.get((String) item.getKey()));
dumpGenerator.writeBooleanField("isFinal",
config.finalParameters.contains(item.getKey()));
String[] resources = config.updatingResource.get(item.getKey());
String resource = UNKNOWN_RESOURCE;
if(resources != null && resources.length > 0) {
resource = resources[0];
}
dumpGenerator.writeStringField("resource", resource);
dumpGenerator.writeEndObject();
}
}
dumpGenerator.writeEndArray();
dumpGenerator.writeEndObject();
dumpGenerator.flush();
}
示例7: dumpConfiguration
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/***
* Dumps the configuration of hierarchy of queues with
* the xml file path given. It is to be used directly ONLY FOR TESTING.
* @param out the writer object to which dump is written to.
* @param configFile the filename of xml file
* @throws IOException
*/
static void dumpConfiguration(Writer out, String configFile,
Configuration conf) throws IOException {
if (conf != null && conf.get(DeprecatedQueueConfigurationParser.
MAPRED_QUEUE_NAMES_KEY) != null) {
return;
}
JsonFactory dumpFactory = new JsonFactory();
JsonGenerator dumpGenerator = dumpFactory.createJsonGenerator(out);
QueueConfigurationParser parser;
boolean aclsEnabled = false;
if (conf != null) {
aclsEnabled = conf.getBoolean(MRConfig.MR_ACLS_ENABLED, false);
}
if (configFile != null && !"".equals(configFile)) {
parser = new QueueConfigurationParser(configFile, aclsEnabled);
}
else {
parser = getQueueConfigurationParser(null, false, aclsEnabled);
}
dumpGenerator.writeStartObject();
dumpGenerator.writeFieldName("queues");
dumpGenerator.writeStartArray();
dumpConfiguration(dumpGenerator,parser.getRoot().getChildren());
dumpGenerator.writeEndArray();
dumpGenerator.writeEndObject();
dumpGenerator.flush();
}
示例8: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(final MediaType mediaType, final JsonGenerator generator, final SerializerProvider provider)
throws IOException {
generator.writeStartObject();
generator.writeFieldName("name");
generator.writeString(mediaType.name());
generator.writeFieldName("displayName");
generator.writeString(mediaType.getDisplayName());
generator.writeEndObject();
}
示例9: serialize
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(
final Object nullKey,
final JsonGenerator jsonGenerator,
final SerializerProvider unused) throws IOException, JsonProcessingException {
jsonGenerator.writeFieldName("");
}
示例10: 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.
}
示例11: 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();
}
示例12: 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();
}
示例13: 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;
}
示例14: writeJsonFields
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names) throws IOException {
super.writeJsonFields(gen, names);
gen.writeFieldName("fields");
gen.writeStartArray();
if (fields != null && fields.size() > 0) {
for (Field field : fields) {
field.writeJSON(gen, names);
}
}
gen.writeEndArray();
}
示例15: writeMap
import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/** Called to write map.*/
private void writeMap(MapSchema mapSchema, Map map, JsonGenerator generator) throws IOException {
Schema valueSchema = mapSchema.getValueSchema();
generator.writeStartObject();
for (Map.Entry<Object, Object> entry : getMapEntries(map)) {
generator.writeFieldName(entry.getKey().toString());
writeValue(valueSchema, entry.getValue(), generator);
}
generator.writeEndObject();
}