use of com.fasterxml.jackson.core.JsonParser in project druid by druid-io.
the class AggregationTestHelper method readQueryResultArrayFromString.
private List readQueryResultArrayFromString(String str) throws Exception {
List result = new ArrayList();
JsonParser jp = mapper.getFactory().createParser(str);
if (jp.nextToken() != JsonToken.START_ARRAY) {
throw new IAE("not an array [%s]", str);
}
ObjectCodec objectCodec = jp.getCodec();
while (jp.nextToken() != JsonToken.END_ARRAY) {
result.add(objectCodec.readValue(jp, toolChest.getResultTypeReference()));
}
return result;
}
use of com.fasterxml.jackson.core.JsonParser in project Gaffer by gchq.
the class RoaringBitmapJsonSerialisationTest method testCanSerialiseAndDeserialise.
@Test
public void testCanSerialiseAndDeserialise() throws IOException {
final ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
RoaringBitmap testBitmap = new RoaringBitmap();
testBitmap.add(2);
testBitmap.add(3000);
testBitmap.add(300000);
for (int i = 400000; i < 500000; i += 2) {
testBitmap.add(i);
}
SERIALISER.serialize(testBitmap, jsonGenerator, null);
jsonGenerator.flush();
byte[] serialisedBitmap = byteArrayBuilder.toByteArray();
JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
parser.setCodec(new ObjectMapper());
Object o = DESERIALISER.deserialize(parser, null);
assertEquals(RoaringBitmap.class, o.getClass());
assertEquals(testBitmap, o);
}
use of com.fasterxml.jackson.core.JsonParser in project Gaffer by gchq.
the class RoaringBitmapJsonSerialisationTest method testCanDeserialiseVersionZeroPointThreePointFourBitmap.
@Test
public void testCanDeserialiseVersionZeroPointThreePointFourBitmap() throws IOException {
//Bitmap of (2,3000,300000) serialised in 0.3.4 Roaring Bitmap base 64 encoded
String serialisedBitmap = "{\"roaringBitmap\":{\"value\":\"OTAAAAIAAAAAAAEABAAAAAIAuAvgkw==\"}}";
RoaringBitmap comparisonBitmap = new RoaringBitmap();
comparisonBitmap.add(2);
comparisonBitmap.add(3000);
comparisonBitmap.add(300000);
JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
parser.setCodec(new ObjectMapper());
Object o = DESERIALISER.deserialize(parser, null);
assertEquals(RoaringBitmap.class, o.getClass());
assertEquals(comparisonBitmap, o);
ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
SERIALISER.serialize((RoaringBitmap) o, jsonGenerator, null);
jsonGenerator.flush();
byte[] bytes = byteArrayBuilder.toByteArray();
String reSerialisedBitmap = new String(bytes);
byteArrayBuilder = new ByteArrayBuilder();
jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
SERIALISER.serialize(comparisonBitmap, jsonGenerator, null);
jsonGenerator.flush();
String serialisedComparisonBitmap = new String(byteArrayBuilder.toByteArray());
assertNotEquals(reSerialisedBitmap, serialisedBitmap);
assertEquals(reSerialisedBitmap, serialisedComparisonBitmap);
}
use of com.fasterxml.jackson.core.JsonParser in project Gaffer by gchq.
the class RoaringBitmapJsonSerialisationTest method testCanSerialiseAndDeserialiseWithRuns.
@Test
public void testCanSerialiseAndDeserialiseWithRuns() throws IOException {
final ByteArrayBuilder byteArrayBuilder = new ByteArrayBuilder();
JsonGenerator jsonGenerator = JSON_FACTORY.createGenerator(byteArrayBuilder);
RoaringBitmap testBitmap = new RoaringBitmap();
testBitmap.add(2);
testBitmap.add(3000);
testBitmap.add(300000);
for (int i = 400000; i < 500000; i += 2) {
testBitmap.add(i);
}
testBitmap.runOptimize();
SERIALISER.serialize(testBitmap, jsonGenerator, null);
jsonGenerator.flush();
byte[] serialisedBitmap = byteArrayBuilder.toByteArray();
JsonParser parser = JSON_FACTORY.createParser(serialisedBitmap);
parser.setCodec(new ObjectMapper());
Object o = DESERIALISER.deserialize(parser, null);
assertEquals(RoaringBitmap.class, o.getClass());
assertEquals(testBitmap, o);
}
use of com.fasterxml.jackson.core.JsonParser in project elasticsearch by elastic.
the class JacksonLocationTests method testLocationExtraction.
public void testLocationExtraction() throws IOException {
// {
// "index" : "test",
// "source" : {
// value : "something"
// }
// }
BytesStreamOutput os = new BytesStreamOutput();
JsonGenerator gen = new JsonFactory().createGenerator(os);
gen.writeStartObject();
gen.writeStringField("index", "test");
gen.writeFieldName("source");
gen.writeStartObject();
gen.writeStringField("value", "something");
gen.writeEndObject();
gen.writeEndObject();
gen.close();
JsonParser parser = new JsonFactory().createParser(os.bytes().streamInput());
assertThat(parser.nextToken(), equalTo(JsonToken.START_OBJECT));
// "index"
assertThat(parser.nextToken(), equalTo(JsonToken.FIELD_NAME));
assertThat(parser.nextToken(), equalTo(JsonToken.VALUE_STRING));
// "source"
assertThat(parser.nextToken(), equalTo(JsonToken.FIELD_NAME));
// JsonLocation location1 = parser.getCurrentLocation();
// parser.skipChildren();
// JsonLocation location2 = parser.getCurrentLocation();
//
// byte[] sourceData = new byte[(int) (location2.getByteOffset() - location1.getByteOffset())];
// System.arraycopy(data, (int) location1.getByteOffset(), sourceData, 0, sourceData.length);
//
// JsonParser sourceParser = new JsonFactory().createJsonParser(new FastByteArrayInputStream(sourceData));
// assertThat(sourceParser.nextToken(), equalTo(JsonToken.START_OBJECT));
// assertThat(sourceParser.nextToken(), equalTo(JsonToken.FIELD_NAME)); // "value"
// assertThat(sourceParser.nextToken(), equalTo(JsonToken.VALUE_STRING));
// assertThat(sourceParser.nextToken(), equalTo(JsonToken.END_OBJECT));
}
Aggregations