Package org.elasticsearch.common.xcontent

Examples of org.elasticsearch.common.xcontent.XContentBuilder.string()


        expected.endObject();

    XContentBuilder actual = fixture.getContentBuilder(event);
   
    JsonParser parser = new JsonParser();
    assertEquals(parser.parse(expected.string()),parser.parse(actual.string()));
  }

  @Test
  public void shouldHandleInvalidJSONDuringComplexParsing() throws Exception {
    ElasticSearchLogStashEventSerializer fixture = new ElasticSearchLogStashEventSerializer();
View Full Code Here


        expected.endObject();

    XContentBuilder actual = fixture.getContentBuilder(event);

    JsonParser parser = new JsonParser();
    assertEquals(parser.parse(expected.string()),parser.parse(actual.string()));
  }
}
View Full Code Here

    try {
      XContentBuilder tmp = jsonBuilder();
      parser = XContentFactory.xContent(contentType).createParser(data);
      parser.nextToken();
      tmp.copyCurrentStructure(parser);
      builder.field(fieldName, tmp.string());
    } catch (JsonParseException ex) {
      // If we get an exception here the most likely cause is nested JSON that
      // can't be figured out in the body. At this point just push it through
      // as is, we have already added the field so don't do it again
      addSimpleField(builder, fieldName, data);
View Full Code Here

        builder.endObject();
      }
      builder.endArray();
    }
    builder.endObject();
    return builder.string();
  }

  /**
   * @param spaceKey to get info for
   * @return spaces indexing info or null if not found.
View Full Code Here

        builder.endObject();
      }
      builder.endArray();
    }
    builder.endObject();
    return builder.string();
  }

  /**
   * @param projectKey to get info for
   * @return project indexing info or null if not found.
View Full Code Here

        builder.endObject();
      }
      builder.endArray();
    }
    builder.endObject();
    return builder.string();
  }

  /**
   * @param spaceKey to get info for
   * @return spaces indexing info or null if not found.
View Full Code Here

    }

    @Test public void testSimpleGenerator() throws Exception {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject().field("test", "value").endObject();
        assertThat(builder.string(), equalTo("{\"test\":\"value\"}"));

        builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject().field("test", "value").endObject();
        assertThat(builder.string(), equalTo("{\"test\":\"value\"}"));
    }
View Full Code Here

        builder.startObject().field("test", "value").endObject();
        assertThat(builder.string(), equalTo("{\"test\":\"value\"}"));

        builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject().field("test", "value").endObject();
        assertThat(builder.string(), equalTo("{\"test\":\"value\"}"));
    }

    @Test public void testOverloadedList() throws Exception {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject().field("test", Lists.newArrayList("1", "2")).endObject();
View Full Code Here

    }

    @Test public void testOverloadedList() throws Exception {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON);
        builder.startObject().field("test", Lists.newArrayList("1", "2")).endObject();
        assertThat(builder.string(), equalTo("{\"test\":[\"1\",\"2\"]}"));
    }

    @Test public void testWritingBinaryToStream() throws Exception {
        FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
View Full Code Here

    }

    @Test public void testFieldCaseConversion() throws Exception {
        XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON).fieldCaseConversion(CAMELCASE);
        builder.startObject().field("test_name", "value").endObject();
        assertThat(builder.string(), equalTo("{\"testName\":\"value\"}"));

        builder = XContentFactory.contentBuilder(XContentType.JSON).fieldCaseConversion(UNDERSCORE);
        builder.startObject().field("testName", "value").endObject();
        assertThat(builder.string(), equalTo("{\"test_name\":\"value\"}"));
    }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.