@Test public void testSmileRawField() throws IOException {
testRawField(XContentType.SMILE);
}
private void testRawField(XContentType type) throws IOException {
XContentBuilder builder = XContentFactory.contentBuilder(type);
builder.startObject();
builder.field("field1", "value1");
builder.rawField("_source", XContentFactory.unCachedContentBuilder(type).startObject().field("s_field", "s_value").endObject().copiedBytes());
builder.field("field2", "value2");
builder.endObject();
XContentParser parser = XContentFactory.xContent(type).createParser(builder.copiedBytes());
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
assertThat(parser.nextToken(), equalTo(XContentParser.Token.FIELD_NAME));
assertThat(parser.currentName(), equalTo("field1"));
assertThat(parser.nextToken(), equalTo(XContentParser.Token.VALUE_STRING));
assertThat(parser.text(), equalTo("value1"));