Package org.elasticsearch.common.jackson.core

Examples of org.elasticsearch.common.jackson.core.JsonGenerator


  private String buildJSONFromFields(Collection<SearchHitField> values) {
    JsonFactory nodeFactory = new JsonFactory();
    try {
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      JsonGenerator generator = nodeFactory.createGenerator(stream, JsonEncoding.UTF8);
      generator.writeStartObject();
      for (SearchHitField value : values) {
        if (value.getValues().size() > 1) {
          generator.writeArrayFieldStart(value.getName());
          for (Object val : value.getValues()) {
            generator.writeObject(val);
          }
          generator.writeEndArray();
        } else {
          generator.writeObjectField(value.getName(), value.getValue());
        }
      }
      generator.writeEndObject();
      generator.flush();
      return new String(stream.toByteArray(), Charset.forName("UTF-8"));
    } catch (IOException e) {
      return null;
    }
  }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.jackson.core.JsonGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.