Java Code Examples for com.fasterxml.jackson.databind.MappingIterator#nextValue()

The following examples show how to use com.fasterxml.jackson.databind.MappingIterator#nextValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReadJsonBuilder.java    From kite with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean doProcess(Record inputRecord, InputStream in) throws IOException {
  Record template = inputRecord.copy();
  removeAttachments(template);
  MappingIterator iter = reader.readValues(in);
  try {
    while (iter.hasNextValue()) {
      Object rootNode = iter.nextValue();
      incrementNumRecords();
      LOG.trace("jsonObject: {}", rootNode);
      
      Record outputRecord = template.copy();
      outputRecord.put(Fields.ATTACHMENT_BODY, rootNode);
      outputRecord.put(Fields.ATTACHMENT_MIME_TYPE, MIME_TYPE);
  
      // pass record to next command in chain:
      if (!getChild().process(outputRecord)) {
        return false;
      }
    }
    return true;
  } finally {
    iter.close();
  }
}
 
Example 2
Source File: NodeDtos.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
protected static <T> List<T> toList(MappingIterator<T> iter) throws java.io.IOException {
    List<T> answer = new ArrayList<>();
    while (iter != null && iter.hasNextValue()) {
        T value = iter.nextValue();
        answer.add(value);
    }
    return answer;
}
 
Example 3
Source File: JsonTemplateLayoutTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    try {
        try (final Socket socket = serverSocket.accept()) {
            final InputStream inputStream = socket.getInputStream();
            while (!closed) {
                final MappingIterator<JsonNode> iterator = JacksonFixture
                        .getObjectMapper()
                        .readerFor(JsonNode.class)
                        .readValues(inputStream);
                while (iterator.hasNextValue()) {
                    final JsonNode value = iterator.nextValue();
                    synchronized (this) {
                        final boolean added = receivedNodes.offer(value);
                        if (!added) {
                            droppedNodeCount++;
                        }
                    }
                }
            }
        }
    } catch (final EOFException ignored) {
        // Socket is closed.
    } catch (final Exception error) {
        if (!closed) {
            throw new RuntimeException(error);
        }
    }
}