Search in sources :

Example 6 with XContentGenerator

use of org.elasticsearch.common.xcontent.XContentGenerator in project elasticsearch by elastic.

the class JsonVsCborTests method testCompareParsingTokens.

public void testCompareParsingTokens() throws IOException {
    BytesStreamOutput xsonOs = new BytesStreamOutput();
    XContentGenerator xsonGen = XContentFactory.xContent(XContentType.CBOR).createGenerator(xsonOs);
    BytesStreamOutput jsonOs = new BytesStreamOutput();
    XContentGenerator jsonGen = XContentFactory.xContent(XContentType.JSON).createGenerator(jsonOs);
    xsonGen.writeStartObject();
    jsonGen.writeStartObject();
    xsonGen.writeStringField("test", "value");
    jsonGen.writeStringField("test", "value");
    xsonGen.writeFieldName("arr");
    xsonGen.writeStartArray();
    jsonGen.writeFieldName("arr");
    jsonGen.writeStartArray();
    xsonGen.writeNumber(1);
    jsonGen.writeNumber(1);
    xsonGen.writeNull();
    jsonGen.writeNull();
    xsonGen.writeEndArray();
    jsonGen.writeEndArray();
    xsonGen.writeEndObject();
    jsonGen.writeEndObject();
    xsonGen.close();
    jsonGen.close();
    verifySameTokens(createParser(JsonXContent.jsonXContent, jsonOs.bytes()), createParser(CborXContent.cborXContent, xsonOs.bytes()));
}
Also used : XContentGenerator(org.elasticsearch.common.xcontent.XContentGenerator) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

XContentGenerator (org.elasticsearch.common.xcontent.XContentGenerator)6 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 BytesRef (org.apache.lucene.util.BytesRef)1 Tuple (org.elasticsearch.common.collect.Tuple)1 XContentParser (org.elasticsearch.common.xcontent.XContentParser)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1