use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project jackson-core by FasterXML.
the class ParserErrorHandlingTest method _testMangledNumbersInt.
private void _testMangledNumbersInt(int mode) throws Exception {
JsonParser p = createParser(mode, "123true");
try {
JsonToken t = p.nextToken();
fail("Should have gotten an exception; instead got token: " + t);
} catch (JsonParseException e) {
verifyException(e, "expected space");
}
p.close();
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project jackson-core by FasterXML.
the class UTF8DataInputJsonParserTest method test_parsePosNumber.
@Test
public void test_parsePosNumber() throws IOException {
byte[] byteArray = new byte[2];
byteArray[0] = (byte) 51;
byteArray[1] = (byte) 22;
IOContext ioContext = new IOContext(new BufferRecycler(), byteArray, false);
InputStream byteArrayInputStream = new ByteArrayInputStream(byteArray);
ByteQuadsCanonicalizer byteQuadsCanonicalizer = ByteQuadsCanonicalizer.createRoot();
DataInputStream dataInputStream = new DataInputStream(byteArrayInputStream);
UTF8DataInputJsonParser uTF8DataInputJsonParser = new UTF8DataInputJsonParser(ObjectReadContext.empty(), ioContext, 1568, dataInputStream, byteQuadsCanonicalizer, 13);
JsonToken jsonToken = uTF8DataInputJsonParser._parsePosNumber(7);
assertEquals(7, jsonToken.id());
assertNull(jsonToken.asString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project syndesis by syndesisio.
the class JsonRecordSupport method jsonStreamToRecords.
public static void jsonStreamToRecords(Set<String> indexes, String dbPath, InputStream is, Consumer<JsonRecord> consumer) throws IOException {
try (JsonParser jp = new JsonFactory().createParser(is)) {
jsonStreamToRecords(indexes, jp, dbPath, consumer);
JsonToken jsonToken = jp.nextToken();
if (jsonToken != null) {
throw new JsonParseException(jp, "Document did not terminate as expected.");
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project debezium by debezium.
the class JacksonReader method parseDocument.
private Document parseDocument(JsonParser parser, boolean nested) throws IOException {
// Iterate over the fields in the top-level document ...
BasicDocument doc = new BasicDocument();
JsonToken token = null;
if (!nested) {
// We expect the START_OBJECT token ...
token = parser.nextToken();
if (!nested && token != JsonToken.START_OBJECT) {
throw new IOException("Expected data to start with an Object, but was " + token);
}
}
String fieldName = null;
token = parser.nextToken();
while (token != JsonToken.END_OBJECT) {
switch(token) {
case FIELD_NAME:
fieldName = parser.getCurrentName();
break;
case START_OBJECT:
doc.setDocument(fieldName, parseDocument(parser, true));
break;
case START_ARRAY:
doc.setArray(fieldName, parseArray(parser, true));
break;
case VALUE_STRING:
doc.setString(fieldName, parser.getValueAsString());
break;
case VALUE_TRUE:
doc.setBoolean(fieldName, true);
break;
case VALUE_FALSE:
doc.setBoolean(fieldName, false);
break;
case VALUE_NULL:
doc.setNull(fieldName);
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
switch(parser.getNumberType()) {
case FLOAT:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getFloatValue());
}
break;
case DOUBLE:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getDoubleValue());
}
break;
case BIG_DECIMAL:
if (handleFloatNumbersAsText) {
doc.setString(fieldName, parser.getText());
} else {
doc.setNumber(fieldName, parser.getDecimalValue());
}
break;
case INT:
doc.setNumber(fieldName, parser.getIntValue());
break;
case LONG:
doc.setNumber(fieldName, parser.getLongValue());
break;
case BIG_INTEGER:
doc.setNumber(fieldName, parser.getBigIntegerValue());
break;
}
break;
case VALUE_EMBEDDED_OBJECT:
// disregard this, since it's an extension ...
break;
case NOT_AVAILABLE:
throw new JsonParseException(parser, "Non-blocking parsers are not supported", parser.getCurrentLocation());
case END_ARRAY:
throw new JsonParseException(parser, "Not expecting an END_ARRAY token", parser.getCurrentLocation());
case END_OBJECT:
throw new JsonParseException(parser, "Not expecting an END_OBJECT token", parser.getCurrentLocation());
}
token = parser.nextToken();
}
return doc;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonToken in project debezium by debezium.
the class JacksonReader method parseArray.
private Array parseArray(JsonParser parser, boolean nested) throws IOException {
// Iterate over the values in the array ...
BasicArray array = new BasicArray();
JsonToken token = null;
if (!nested) {
// We expect the START_ARRAY token ...
token = parser.nextToken();
if (!nested && token != JsonToken.START_ARRAY) {
throw new IOException("Expected data to start with an Array, but was " + token);
}
}
token = parser.nextToken();
while (token != JsonToken.END_ARRAY) {
switch(token) {
case START_OBJECT:
array.add(parseDocument(parser, true));
break;
case START_ARRAY:
array.add(parseArray(parser, true));
break;
case VALUE_STRING:
array.add(parser.getValueAsString());
break;
case VALUE_TRUE:
array.add(true);
break;
case VALUE_FALSE:
array.add(false);
break;
case VALUE_NULL:
array.addNull();
break;
case VALUE_NUMBER_FLOAT:
case VALUE_NUMBER_INT:
switch(parser.getNumberType()) {
case FLOAT:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getFloatValue());
}
break;
case DOUBLE:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getDoubleValue());
}
break;
case BIG_DECIMAL:
if (handleFloatNumbersAsText) {
array.add(parser.getText());
} else {
array.add(parser.getDecimalValue());
}
break;
case INT:
array.add(parser.getIntValue());
break;
case LONG:
array.add(parser.getLongValue());
break;
case BIG_INTEGER:
array.add(parser.getBigIntegerValue());
break;
}
break;
case VALUE_EMBEDDED_OBJECT:
// disregard this, since it's an extension ...
break;
case NOT_AVAILABLE:
throw new JsonParseException(parser, "Non-blocking parsers are not supported", parser.getCurrentLocation());
case FIELD_NAME:
throw new JsonParseException(parser, "Not expecting a FIELD_NAME token", parser.getCurrentLocation());
case END_ARRAY:
throw new JsonParseException(parser, "Not expecting an END_ARRAY token", parser.getCurrentLocation());
case END_OBJECT:
throw new JsonParseException(parser, "Not expecting an END_OBJECT token", parser.getCurrentLocation());
}
token = parser.nextToken();
}
return array;
}
Aggregations