當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonGenerator.writeEndObject方法代碼示例

本文整理匯總了Java中org.codehaus.jackson.JsonGenerator.writeEndObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JsonGenerator.writeEndObject方法的具體用法?Java JsonGenerator.writeEndObject怎麽用?Java JsonGenerator.writeEndObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.codehaus.jackson.JsonGenerator的用法示例。


在下文中一共展示了JsonGenerator.writeEndObject方法的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();
}
 
開發者ID:CyberAgent,項目名稱:embulk-input-parquet_hadoop,代碼行數:24,代碼來源:CSVAsJSONIterator.java

示例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);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:JSONBean.java

示例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();
}
 
開發者ID:oracle,項目名稱:bdglue,代碼行數:26,代碼來源:JsonEncoder.java

示例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);
    }
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:29,代碼來源:Schema.java

示例5: write

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Used to write the state of the SessionManager 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();
  // retiredSessions and numRetiredSessions need not be persisted

  // sessionCounter can be set to 0, when the SessionManager is instantiated

  // sessions begins
  jsonGenerator.writeFieldName("sessions");
  jsonGenerator.writeStartObject();
  for (String sessionId : sessions.keySet()) {
    jsonGenerator.writeFieldName(sessionId);
    sessions.get(sessionId).write(jsonGenerator);
  }
  jsonGenerator.writeEndObject();
  // sessions ends

  jsonGenerator.writeNumberField("sessionCounter",
                                  sessionCounter.longValue());

  jsonGenerator.writeEndObject();

  // We can rebuild runnableSessions
  // No need to write startTime and numRetiredSessions
}
 
開發者ID:rhli,項目名稱:hadoop-EAR,代碼行數:32,代碼來源:SessionManager.java

示例6: 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());
    }
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:41,代碼來源:JMXJsonServlet.java

示例7: 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;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:50,代碼來源:Log4Json.java

示例8: 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();
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:41,代碼來源:Configuration.java

示例9: 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();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:36,代碼來源:QueueManager.java

示例10: 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();
}
 
開發者ID:cerner,項目名稱:jwala,代碼行數:11,代碼來源:MediaTypeSerializer.java

示例11: serialize

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(ScimGroup scimGroup, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("displayName");
            /*
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            attributes.add("meta.resourceType");
            */
        }

        JsonNode rootNode = mapper.convertValue(scimGroup, JsonNode.class);

        processNodes(null, rootNode, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:38,代碼來源:GluuGroupListSerializer.java

示例12: serialize

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(ScimPerson scimPerson, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("userName");
            /*
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            */
        }

        JsonNode rootNode = mapper.convertValue(scimPerson, JsonNode.class);

        processNodes(null, rootNode, mapper, scimPerson, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:37,代碼來源:GluuCustomPersonListSerializer.java

示例13: serialize

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(User user, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

    log.info(" serialize() ");

    try {

        jsonGenerator.writeStartObject();

        ObjectMapper mapper = new ObjectMapper();
        mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

        attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
        // attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(mapper.readValue(attributesArray, String[].class))) : null;
        if (attributes != null && attributes.size() > 0) {
            attributes.add("schemas");
            attributes.add("id");
            attributes.add("userName");
            attributes.add("meta.created");
            attributes.add("meta.lastModified");
            attributes.add("meta.location");
            attributes.add("meta.version");
            attributes.add("meta.resourceType");
        }

        JsonNode rootNode = mapper.convertValue(user, JsonNode.class);

        processNodes(null, rootNode, mapper, user, jsonGenerator);

        jsonGenerator.writeEndObject();

    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:37,代碼來源:ListResponseUserSerializer.java

示例14: serialize

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
public void serialize(FidoDevice fidoDevice, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {

	log.info(" serialize() ");

	try {

		jsonGenerator.writeStartObject();

		ObjectMapper mapper = new ObjectMapper();
		mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);

		attributes = (attributesArray != null && !attributesArray.isEmpty()) ? new LinkedHashSet<String>(Arrays.asList(attributesArray.split("\\,"))) : null;
		if (attributes != null && attributes.size() > 0) {
			attributes.add("schemas");
			attributes.add("id");
			attributes.add("userId");
			attributes.add("displayName");
               attributes.add("meta.created");
               attributes.add("meta.lastModified");
               attributes.add("meta.location");
               attributes.add("meta.version");
			attributes.add("meta.resourceType");
		}

		JsonNode rootNode = mapper.convertValue(fidoDevice, JsonNode.class);

		processNodes(null, rootNode, mapper, fidoDevice, jsonGenerator);

		jsonGenerator.writeEndObject();

	} catch (Exception e) {
		e.printStackTrace();
		throw new IOException(INTERNAL_SERVER_ERROR_MESSAGE);
	}
}
 
開發者ID:AgarwalNeha1,項目名稱:gluu,代碼行數:37,代碼來源:ListResponseFidoDeviceSerializer.java

示例15: 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


注:本文中的org.codehaus.jackson.JsonGenerator.writeEndObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。