Java Code Examples for org.elasticsearch.common.xcontent.XContentGenerator#writeNull()

The following examples show how to use org.elasticsearch.common.xcontent.XContentGenerator#writeNull() . 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: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeMultiReference(
    XContentGenerator generator, int depth, int maxDepth, Iterable<Entity> mrefEntities)
    throws IOException {
  if (!Iterables.isEmpty(mrefEntities)) {
    generator.writeStartArray();
    for (Entity mrefEntity : mrefEntities) {
      createRecReferenceAttribute(generator, depth, maxDepth, mrefEntity);
    }
    generator.writeEndArray();
  } else {
    generator.writeNull();
  }
}
 
Example 2
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeReference(
    XContentGenerator generator, int depth, int maxDepth, Entity xrefEntity) throws IOException {
  if (xrefEntity != null) {
    createRecReferenceAttribute(generator, depth, maxDepth, xrefEntity);
  } else {
    generator.writeNull();
  }
}
 
Example 3
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeString(XContentGenerator generator, String strValue) throws IOException {
  if (strValue != null) {
    generator.writeString(strValue);
  } else {
    generator.writeNull();
  }
}
 
Example 4
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeDate(XContentGenerator generator, LocalDate dateValue) throws IOException {
  if (dateValue != null) {
    generator.writeString(dateValue.toString());
  } else {
    generator.writeNull();
  }
}
 
Example 5
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeDateTime(XContentGenerator generator, Instant dateTimeValue)
    throws IOException {
  if (dateTimeValue != null) {
    generator.writeString(dateTimeValue.toString());
  } else {
    generator.writeNull();
  }
}
 
Example 6
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeLong(XContentGenerator generator, Long longValue) throws IOException {
  if (longValue != null) {
    generator.writeNumber(longValue);
  } else {
    generator.writeNull();
  }
}
 
Example 7
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeInteger(XContentGenerator generator, Integer intValue) throws IOException {
  if (intValue != null) {
    generator.writeNumber(intValue);
  } else {
    generator.writeNull();
  }
}
 
Example 8
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeDouble(XContentGenerator generator, Double doubleValue) throws IOException {
  if (doubleValue != null) {
    generator.writeNumber(doubleValue);
  } else {
    generator.writeNull();
  }
}
 
Example 9
Source File: DocumentContentBuilder.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void writeBoolean(XContentGenerator generator, Boolean boolValue) throws IOException {
  if (boolValue != null) {
    generator.writeBoolean(boolValue);
  } else {
    generator.writeNull();
  }
}
 
Example 10
Source File: XmlXContentGenerator.java    From elasticsearch-xml with Apache License 2.0 4 votes vote down vote up
public static void copyCurrentEvent(XContentGenerator generator, XContentParser parser) throws IOException {
    switch (parser.currentToken()) {
        case START_OBJECT:
            generator.writeStartObject();
            break;
        case END_OBJECT:
            generator.writeEndObject();
            break;
        case START_ARRAY:
            generator.writeStartArray();
            break;
        case END_ARRAY:
            generator.writeEndArray();
            break;
        case FIELD_NAME:
            generator.writeFieldName(parser.currentName());
            break;
        case VALUE_STRING:
            if (parser.hasTextCharacters()) {
                generator.writeString(parser.textCharacters(), parser.textOffset(), parser.textLength());
            } else {
                generator.writeString(parser.text());
            }
            break;
        case VALUE_NUMBER:
            switch (parser.numberType()) {
                case INT:
                    generator.writeNumber(parser.intValue());
                    break;
                case LONG:
                    generator.writeNumber(parser.longValue());
                    break;
                case FLOAT:
                    generator.writeNumber(parser.floatValue());
                    break;
                case DOUBLE:
                    generator.writeNumber(parser.doubleValue());
                    break;
            }
            break;
        case VALUE_BOOLEAN:
            generator.writeBoolean(parser.booleanValue());
            break;
        case VALUE_NULL:
            generator.writeNull();
            break;
        case VALUE_EMBEDDED_OBJECT:
            generator.writeBinary(parser.binaryValue());
    }
}