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

The following examples show how to use org.elasticsearch.common.xcontent.XContentGenerator#writeString() . 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 writeString(XContentGenerator generator, String strValue) throws IOException {
  if (strValue != null) {
    generator.writeString(strValue);
  } 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 writeDate(XContentGenerator generator, LocalDate dateValue) throws IOException {
  if (dateValue != null) {
    generator.writeString(dateValue.toString());
  } 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 writeDateTime(XContentGenerator generator, Instant dateTimeValue)
    throws IOException {
  if (dateTimeValue != null) {
    generator.writeString(dateTimeValue.toString());
  } else {
    generator.writeNull();
  }
}
 
Example 4
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());
    }
}