Exemplo n.º 1
0
 /**
  * Method called after an object field has been output, but before the value is output.
  *
  * <p>Default handling (without pretty-printing) will output a single colon to separate the two.
  * Pretty-printer is to output a colon as well, but can surround that with other (white-space)
  * decoration.
  */
 @Override
 public void writeObjectFieldValueSeparator(JsonGenerator jg) throws IOException {
   if (_spacesInObjectEntries) {
     jg.writeRaw(" : ");
   } else {
     jg.writeRaw(':');
   }
 }
Exemplo n.º 2
0
 @Override
 public void writeEndArray(JsonGenerator gen, int nrOfValues) throws IOException {
   if (!_arrayIndenter.isInline()) {
     --_nesting;
   }
   if (nrOfValues > 0) {
     _arrayIndenter.writeIndentation(gen, _nesting);
   } else {
     gen.writeRaw(' ');
   }
   gen.writeRaw(']');
 }
Exemplo n.º 3
0
 @Override
 public void writeEndObject(JsonGenerator jg, int nrOfEntries) throws IOException {
   if (!_objectIndenter.isInline()) {
     --_nesting;
   }
   if (nrOfEntries > 0) {
     _objectIndenter.writeIndentation(jg, _nesting);
   } else {
     jg.writeRaw(' ');
   }
   jg.writeRaw('}');
 }
 @Override
 public void serialize(
     final JsonBuilder json,
     final JsonGenerator jsonGenerator,
     final SerializerProvider serializerProvider)
     throws IOException, JsonGenerationException {
   // the JSON from the builder will already be started/ended as array or object...just need to
   // surround it
   // with appropriate chars to fit into the serialization pattern.
   jsonGenerator.writeRaw(":");
   jsonGenerator.writeRaw(json.toString());
   jsonGenerator.writeRaw(",");
 }
Exemplo n.º 5
0
 @Override
 public void writeStartArray(JsonGenerator jg) throws IOException {
   if (!_arrayIndenter.isInline()) {
     ++_nesting;
   }
   jg.writeRaw('[');
 }
  @Override
  protected void renderMergedOutputModel(
      Map<String, Object> model, HttpServletRequest request, HttpServletResponse response)
      throws Exception {

    OutputStream stream =
        this.updateContentLength ? createTemporaryOutputStream() : response.getOutputStream();

    Object value = filterModel(model);
    JsonGenerator generator =
        this.objectMapper.getJsonFactory().createJsonGenerator(stream, this.encoding);

    // A workaround for JsonGenerators not applying serialization features
    // https://github.com/FasterXML/jackson-databind/issues/12
    if (this.objectMapper.isEnabled(SerializationFeature.INDENT_OUTPUT)) {
      generator.useDefaultPrettyPrinter();
    }

    if (this.prefixJson) {
      generator.writeRaw("{} && ");
    }
    this.objectMapper.writeValue(generator, value);

    if (this.updateContentLength) {
      writeToResponse(response, (ByteArrayOutputStream) stream);
    }
  }
Exemplo n.º 7
0
 @Override
 public void writeStartObject(JsonGenerator jg) throws IOException {
   jg.writeRaw('{');
   if (!_objectIndenter.isInline()) {
     ++_nesting;
   }
 }
Exemplo n.º 8
0
  @Ignore
  @Test
  public void testBulkUpdate() throws IOException {

    ResetBasicData.reset();

    EbeanServer server = Ebean.getServer(null);
    JsonContext jsonContext = server.json();

    StringWriter writer = new StringWriter();
    JsonGenerator generator = jsonContext.createGenerator(writer);

    List<Customer> customers = Ebean.find(Customer.class).findList();

    for (Customer customer : customers) {

      customer.setName(customer.getName() + "esMod");
      PathProperties updateProps = PathProperties.parse("name");

      generator.writeStartObject();
      generator.writeFieldName("update");
      generator.writeStartObject();
      generator.writeStringField("_id", customer.getId().toString());
      generator.writeStringField("_type", "customer");
      generator.writeStringField("_index", "customer");
      generator.writeEndObject();
      generator.writeEndObject();
      generator.writeRaw("\n");

      generator.writeStartObject();
      generator.writeFieldName("doc");
      jsonContext.toJson(customer, generator, updateProps);
      generator.writeEndObject();
      generator.writeRaw("\n");
    }

    generator.close();
    String json = writer.toString();

    post("http://localhost:9200/_bulk", json);

    // curl -s -XPOST localhost:9200/_bulk

    //    { "update" : {"_id" : "1", "_type" : "type1", "_index" : "index1"} }
    //    { "doc" : {"field2" : "value2"} }

  }
 @Override
 public void write(Record record) throws IOException {
   if (closed) {
     throw new IOException("writer has been closed");
   }
   generator.writeObject(BeanHelper.wrapRecord(record));
   generator.writeRaw('\n');
 }
  @Test
  public void testCreateGenerator_writeRaw() throws Exception {

    EbeanServer server = Ebean.getDefaultServer();

    StringWriter writer = new StringWriter();
    JsonContext json = server.json();
    JsonGenerator generator = json.createGenerator(writer);

    // test that we can write anything via writeRaw()
    generator.writeRaw("START");
    generator.writeStartArray();
    generator.writeStartObject();
    generator.writeNumberField("count", 12);
    generator.writeEndObject();
    generator.writeEndArray();
    generator.writeRaw("END");
    generator.close();

    assertEquals("START[{\"count\":12}]END", writer.toString());
  }
Exemplo n.º 11
0
 @Override
 public void writeIndentation(JsonGenerator jg, int level) throws IOException {
   jg.writeRaw(' ');
 }
Exemplo n.º 12
0
 /**
  * Method called after an array value has been completely output, and before another value is to
  * be output.
  *
  * <p>Default handling (without pretty-printing) will output a single comma to separate the two.
  * Pretty-printer is to output a comma as well, but can surround that with other (white-space)
  * decoration.
  */
 @Override
 public void writeArrayValueSeparator(JsonGenerator gen) throws IOException {
   gen.writeRaw(',');
   _arrayIndenter.writeIndentation(gen, _nesting);
 }
Exemplo n.º 13
0
 /**
  * Method called after an object entry (field:value) has been completely output, and before
  * another value is to be output.
  *
  * <p>Default handling (without pretty-printing) will output a single comma to separate the two.
  * Pretty-printer is to output a comma as well, but can surround that with other (white-space)
  * decoration.
  */
 @Override
 public void writeObjectEntrySeparator(JsonGenerator jg) throws IOException {
   jg.writeRaw(',');
   _objectIndenter.writeIndentation(jg, _nesting);
 }
Exemplo n.º 14
0
 @Override
 public void writeRootValueSeparator(JsonGenerator jg) throws IOException {
   if (_rootSeparator != null) {
     jg.writeRaw(_rootSeparator);
   }
 }
 @Override
 public void writeArrayValueSeparator(JsonGenerator g) throws IOException {
   g.writeRaw(" , ");
 }