Search in sources :

Example 1 with JSONStreamVisitor

use of com.ociweb.pronghorn.util.parse.JSONStreamVisitor in project PronghornPipes by oci-pronghorn.

the class JSONParserTest method streamingArrayTest.

@Test
public void streamingArrayTest() {
    String json = " [ { \"key\" : \"value\" } , \n { \"key\" : \"value\" }     ] ";
    Pipe pipe = buildPopulatedPipe(json);
    TrieParserReader reader = new TrieParserReader(2);
    int msgIdx = Pipe.takeMsgIdx(pipe);
    TrieParserReader.parseSetup(reader, pipe);
    StringBuilder target = new StringBuilder();
    JSONStreamVisitor visitor = new JSONStreamVisitorCapture(target);
    Pipe.takeMsgIdx(pipe);
    JSONStreamParser parser = new JSONStreamParser();
    parser.parse(reader, visitor);
    assertEquals(target.toString().replaceAll("\n", "\\n"), "[{\n    \"key\":\"value\"}\n,\n{\n    \"key\":\"value\"}\n]", target.toString());
}
Also used : JSONStreamVisitor(com.ociweb.pronghorn.util.parse.JSONStreamVisitor) JSONStreamParser(com.ociweb.pronghorn.util.parse.JSONStreamParser) Pipe(com.ociweb.pronghorn.pipe.Pipe) JSONStreamVisitorCapture(com.ociweb.pronghorn.util.parse.JSONStreamVisitorCapture) Test(org.junit.Test)

Aggregations

Pipe (com.ociweb.pronghorn.pipe.Pipe)1 JSONStreamParser (com.ociweb.pronghorn.util.parse.JSONStreamParser)1 JSONStreamVisitor (com.ociweb.pronghorn.util.parse.JSONStreamVisitor)1 JSONStreamVisitorCapture (com.ociweb.pronghorn.util.parse.JSONStreamVisitorCapture)1 Test (org.junit.Test)1