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


Java JsonGenerator.writeStartArray方法代碼示例

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


在下文中一共展示了JsonGenerator.writeStartArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Writes the records schema in JSON format
 *
 * @param writer   JSON writer
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the record schema
 */
@Override
protected void writeJsonFields(JsonGenerator writer, SchemaNames names, String encSpace)
        throws IOException {
    super.writeJsonFields(writer, names, encSpace);

    // we allow reading for empty fields, so writing of records with empty fields are allowed as well
    if (_request) {
        writer.writeFieldName("request");
    } else {
        writer.writeFieldName("fields");
    }
    writer.writeStartArray();

    if (_fields != null && !_fields.isEmpty()) {
        for (Field field : this) {
            field.writeJson(writer, names, getNamespace()); // use the namespace of the record for the fields
        }
    }
    writer.writeEndArray();
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:28,代碼來源:RecordSchema.java

示例2: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Writes named schema in JSON format
 *
 * @param gen      JSON generator
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the schema
 */
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names, String encSpace) throws IOException {
    _schemaName.writeJson(gen, names);

    if (_doc != null && !_doc.isEmpty()) {
        gen.writeFieldName("doc");
        gen.writeString(_doc);
    }

    if (_aliases != null) {
        gen.writeFieldName("aliases");
        gen.writeStartArray();
        for (SchemaName name : _aliases) {
            String fullname = name.getSpace() != null ? name.getSpace() + "." + name.getName() : name.getName();
            gen.writeString(fullname);
        }
        gen.writeEndArray();
    }
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:27,代碼來源:NamedSchema.java

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

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

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

示例6: encodeMap

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void encodeMap(Map<String, Object> event, JsonGenerator generator)
        throws IOException, JsonGenerationException,
        JsonProcessingException {
    generator.writeStartObject();
    for (Map.Entry<String, Object> x : event.entrySet()) {
        generator.writeFieldName(x.getKey());
        if (x.getValue() == null) {
            //We assume all value type should be primitive.
            generator.writeObject(x.getValue());
        } else if (Map.class.isAssignableFrom(x.getValue().getClass())) {
            encodeMap((Map<String, Object>) x.getValue(), generator);
        } else if (x.getValue().getClass().isArray()) {
            generator.writeStartArray();
            int length = Array.getLength(x.getValue());
            for (int i = 0; i < length; i++) {
                generator.writeObject(Array.get(x.getValue(), i));    
            }
            generator.writeEndArray();
        } else if (x.getValue() instanceof Collection) {
            generator.writeStartArray();
            Iterator iterator = ((Collection) (x.getValue())).iterator();
            while (iterator.hasNext()) {
                generator.writeObject(iterator.next());    
            }
            generator.writeEndArray();
        } else {
            generator.writeObject(x.getValue());
        }
    }
    generator.writeEndObject();
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:33,代碼來源:AvroMessageSerializer.java

示例7: writeArray

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/** Called to write array.*/
private void writeArray(ArraySchema arraySchema, List array, JsonGenerator generator) throws IOException {
    Schema itemSchema = arraySchema.getItemSchema();
    generator.writeStartArray();
    for (Iterator iterator = getArrayElements(array); iterator.hasNext();) {
        writeValue(itemSchema, iterator.next(), generator);
    }
    generator.writeEndArray();
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:10,代碼來源:SpecificJsonWriter.java

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

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

示例10: generateEntry

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private void generateEntry(JsonGenerator generator,
        Map.Entry<String, Object> x) throws IOException,
        JsonGenerationException, JsonProcessingException {
    if (x.getValue() == null) {
        if (!filterOutNullValue) {
            generator.writeFieldName(x.getKey());
            generator.writeNull();
        }
        return;
    }

    generator.writeFieldName(x.getKey());
    if (Map.class.isAssignableFrom(x.getValue().getClass())) {
        encodeMap((Map<String, Object>) x.getValue(), generator);
    } else if (x.getValue().getClass().isArray()) {
        generator.writeStartArray();
        int length = Array.getLength(x.getValue());
        for (int i = 0; i < length; i++) {
            generator.writeObject(Array.get(x.getValue(), i));    
        }
        generator.writeEndArray();
    } else if (x.getValue() instanceof Collection) {
        generator.writeStartArray();
        Iterator iterator = ((Collection) (x.getValue())).iterator();
        while (iterator.hasNext()) {
            generator.writeObject(iterator.next());    
        }
        generator.writeEndArray();
    } else {
        generator.writeObject(x.getValue());
    }
}
 
開發者ID:pulsarIO,項目名稱:jetstream,代碼行數:34,代碼來源:JSONMessageSerializer.java

示例11: serializeTransaction

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
private static void serializeTransaction(Transaction transaction, JsonGenerator g) throws IOException {
    g.writeStartObject();
    writeSimpleProperty(g, "id", transaction.getTransactionId());
    writeSimpleProperty(g, "creationTimestamp", transaction.getCreationTimestamp());

    if (transaction.getPreparedTasks() != null && !transaction.getPreparedTasks().isEmpty()) {
        g.writeFieldName("preparedTasks");
        g.writeStartArray();
        for (Task t : transaction.getPreparedTasks()) {
            serializeTask(t, g);
        }
        g.writeEndArray();
    }
    g.writeEndObject();
}
 
開發者ID:diennea,項目名稱:majordodo,代碼行數:16,代碼來源:BrokerStatusSnapshot.java

示例12: writeJSON

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
protected void writeJSON(JsonGenerator gen, SchemaNames names) throws IOException {
    gen.writeStartArray();
    for (Schema schema : schemas) {
        schema.writeJSON(gen, names);
    }
    gen.writeEndArray();
}
 
開發者ID:adohe,項目名稱:Bottlenose,代碼行數:9,代碼來源:UnionSchema.java

示例13: writeJson

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
/**
 * Writes union schema in JSON format
 *
 * @param writer
 * @param names    list of named schemas already written
 * @param encSpace enclosing namespace of the schema
 */
protected void writeJson(JsonGenerator writer, SchemaNames names,
                         String encSpace)
        throws IOException {
    writer.writeStartArray();
    for (Schema schema : _schemas) {
        schema.writeJson(writer, names, encSpace);
    }
    writer.writeEndArray();
}
 
開發者ID:archcentric,項目名稱:BaijiSerializer4J,代碼行數:17,代碼來源:UnionSchema.java

示例14: writeJsonFields

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@Override
protected void writeJsonFields(JsonGenerator gen, SchemaNames names) throws IOException {
    super.writeJsonFields(gen, names);
    gen.writeFieldName("symbols");
    gen.writeStartArray();
    for (String symbol : symbols) {
        gen.writeString(symbol);
    }
    gen.writeEndArray();
}
 
開發者ID:adohe,項目名稱:Bottlenose,代碼行數:11,代碼來源:EnumSchema.java

示例15: energizationStreaming

import org.codehaus.jackson.JsonGenerator; //導入方法依賴的package包/類
@POST
@Path("/streaming")
public Response energizationStreaming(String body, @Context GraphDatabaseService db) throws IndexNotFoundKernelException, IOException, SchemaRuleNotFoundException, IndexBrokenKernelException, EntityNotFoundException {
    HashMap input = Validators.getValidEquipmentIds(body);
    StreamingOutput stream = os -> {
        JsonGenerator jg = objectMapper.getJsonFactory().createJsonGenerator(os, JsonEncoding.UTF8);
        jg.writeStartArray();

        try (Transaction tx = db.beginTx()) {
            ThreadToStatementContextBridge ctx = dbapi.getDependencyResolver().resolveDependency(ThreadToStatementContextBridge.class);
            ReadOperations ops = ctx.get().readOperations();
            IndexDescriptor descriptor = ops.indexGetForLabelAndPropertyKey(equipmentLabelId, propertyEquipmentId);

            HashMap<Long, Double> equipmentMap = new HashMap<>();
            for (String equipmentId : (Collection<String>) input.get("ids")) {
                Cursor<NodeItem> nodes = ops.nodeCursorGetFromUniqueIndexSeek(descriptor, equipmentId);
                if (nodes.next()) {
                    long equipmentNodeId = nodes.get().id();
                    energized.add((int) equipmentNodeId);
                    jg.writeString(equipmentId);
                    equipmentMap.put(equipmentNodeId, (double) ops.nodeGetProperty(equipmentNodeId, propertyVoltage));

                    while (!equipmentMap.isEmpty()) {
                        Map.Entry<Long, Double> entry = equipmentMap.entrySet().iterator().next();
                        equipmentMap.remove(entry.getKey());
                        RelationshipIterator relationshipIterator = ops.nodeGetRelationships(entry.getKey(), org.neo4j.graphdb.Direction.BOTH);
                        Cursor<RelationshipItem> c;

                        while (relationshipIterator.hasNext()) {
                            c = ops.relationshipCursor(relationshipIterator.next());
                            if (c.next() && (boolean) c.get().getProperty(propertyIncomingSwitchOn) && (boolean) c.get().getProperty(propertyOutgoingSwitchOn)) {
                                long otherNodeId = c.get().otherNode(entry.getKey());
                                if (!energized.contains((int) otherNodeId)) {
                                    double newVoltage = (double) ops.nodeGetProperty(otherNodeId, propertyVoltage);
                                    if (newVoltage <= entry.getValue()) {
                                        jg.writeString((String) ops.nodeGetProperty(otherNodeId, propertyEquipmentId));
                                        energized.add((int) otherNodeId);
                                        equipmentMap.put(otherNodeId, newVoltage);
                                    }
                                }
                            }
                        }
                    }
                }
                nodes.close();
            }
            tx.success();
        } catch (Exception e) {
            e.printStackTrace();
        }

        jg.writeEndArray();
        jg.flush();
        jg.close();
    };
    return Response.ok().entity(stream).type(MediaType.APPLICATION_JSON).build();
}
 
開發者ID:maxdemarzi,項目名稱:power_grid,代碼行數:58,代碼來源:Energization.java


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