use of com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class JsonReader method write.
@Override
public ReadState write(ComplexWriter writer) throws IOException {
ReadState readState = null;
try {
JsonToken t = lastSeenJsonToken;
if (t == null || t == JsonToken.END_OBJECT) {
t = parser.nextToken();
}
while (!parser.hasCurrentToken() && !parser.isClosed()) {
t = parser.nextToken();
}
lastSeenJsonToken = null;
if (parser.isClosed()) {
return ReadState.END_OF_STREAM;
}
readState = writeToVector(writer, t);
switch(readState) {
case END_OF_STREAM:
break;
case WRITE_SUCCEED:
break;
default:
throw getExceptionWithContext(UserException.dataReadError(), currentFieldName, null).message("Failure while reading JSON. (Got an invalid read state %s )", readState.toString()).build(logger);
}
} catch (com.fasterxml.jackson.core.JsonParseException ex) {
if (ignoreJSONParseError()) {
if (processJSONException() == JsonExceptionProcessingState.END_OF_STREAM) {
return ReadState.JSON_RECORD_PARSE_EOF_ERROR;
} else {
return ReadState.JSON_RECORD_PARSE_ERROR;
}
} else {
throw ex;
}
}
return readState;
}
use of com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class VectorOutput method innerRun.
protected boolean innerRun() throws IOException {
JsonToken t = parser.nextToken();
if (t != JsonToken.FIELD_NAME) {
return false;
}
String possibleTypeName = parser.getText();
if (!possibleTypeName.isEmpty() && possibleTypeName.charAt(0) == '$') {
switch(possibleTypeName) {
case ExtendedTypeName.BINARY:
writeBinary(checkNextToken(JsonToken.VALUE_STRING));
checkCurrentToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.TYPE:
if (checkNextToken(JsonToken.VALUE_NUMBER_INT) || !hasBinary()) {
throw UserException.parseError().message("Either $type is not an integer or has no $binary").build(LOG);
}
writeBinary(checkNextToken(JsonToken.VALUE_STRING));
checkCurrentToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.DATE:
writeDate(checkNextToken(JsonToken.VALUE_STRING));
checkNextToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.TIME:
writeTime(checkNextToken(JsonToken.VALUE_STRING));
checkNextToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.TIMESTAMP:
writeTimestamp(checkNextToken(JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT));
checkNextToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.INTERVAL:
writeInterval(checkNextToken(JsonToken.VALUE_STRING));
checkNextToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.INTEGER:
writeInteger(checkNextToken(JsonToken.VALUE_STRING, JsonToken.VALUE_NUMBER_INT));
checkNextToken(JsonToken.END_OBJECT);
return true;
case ExtendedTypeName.DECIMAL:
writeDecimal(checkNextToken(JsonToken.VALUE_NUMBER_FLOAT, JsonToken.VALUE_NUMBER_INT));
checkNextToken(JsonToken.END_OBJECT);
return true;
}
}
return false;
}
use of com.fasterxml.jackson.core.JsonToken in project drill by apache.
the class BaseJsonProcessor method processJSONException.
/*
* DRILL - 4653 This method processes JSON tokens until it reaches end of the
* current line when it processes start of a new JSON line { - return
* PROC_SUCCEED when it sees EOF the stream - there may not be a closing }
*/
protected JsonExceptionProcessingState processJSONException() throws IOException {
while (!parser.isClosed()) {
try {
JsonToken currentToken = parser.nextToken();
if (currentToken == JsonToken.START_OBJECT && (lastSeenJsonToken == JsonToken.END_OBJECT || lastSeenJsonToken == null)) {
lastSeenJsonToken = currentToken;
break;
}
lastSeenJsonToken = currentToken;
} catch (com.fasterxml.jackson.core.JsonParseException ex1) {
if (ex1.getOriginalMessage().startsWith(JACKSON_PARSER_EOF_FILE_MSG)) {
return JsonExceptionProcessingState.END_OF_STREAM;
}
continue;
}
}
return JsonExceptionProcessingState.PROC_SUCCEED;
}
use of com.fasterxml.jackson.core.JsonToken in project geode by apache.
the class JSONFormatter method getList.
private PdxListHelper getList(JsonParser jp, states currentState, PdxListHelper currentPdxList) throws JsonParseException, IOException {
String currentFieldName = null;
currentPdxList = new PdxListHelper(currentPdxList, null);
while (true) {
JsonToken nt = jp.nextToken();
if (nt == null) {
return currentPdxList;
}
switch(nt) {
case START_OBJECT:
{
objectStarts(currentState);
currentState = states.OBJECT_START;
// need to create new PdxInstance
// root object will not name, so create classname lazily from all members.
// child object will have name; but create this as well lazily from all members
JSONToPdxMapper tmp = getPdxInstance(jp, currentState, null);
currentPdxList.addObjectField(currentFieldName, tmp);
currentState = states.OBJECT_ENDS;
break;
}
case END_OBJECT:
{
// pdxinstnce ends
throw new IllegalStateException("getList got token END_OBJECT while current state is " + currentState);
}
case FIELD_NAME:
{
throw new IllegalStateException("getList got token FIELD_NAME while current state is " + currentState);
}
case NOT_AVAILABLE:
{
throw new IllegalStateException("NOT_AVAILABLE token found in getList current state is " + currentState);
// break;
}
case START_ARRAY:
{
// need to create array; fieldname may be there; will it case it not there
arrayStarts(currentState);
PdxListHelper tmp = currentPdxList.addListField();
currentPdxList = tmp;
currentState = states.LIST_FOUND;
break;
}
case END_ARRAY:
{
// array is end
arrayEnds(currentState);
currentState = states.LIST_ENDS;
if (currentPdxList.getParent() == null) {
return currentPdxList;
}
currentPdxList = currentPdxList.getParent();
break;
}
case VALUE_EMBEDDED_OBJECT:
{
throw new IllegalStateException("VALUE_EMBEDDED_OBJECT token found");
}
case VALUE_FALSE:
{
// write boolen
boolFound(currentState);
currentState = states.SCALAR_FOUND;
currentPdxList.addBooleanField(jp.getBooleanValue());
break;
}
case VALUE_NULL:
{
// write null
nullFound(currentState);
currentState = states.SCALAR_FOUND;
currentPdxList.addNullField(null);
break;
}
case VALUE_NUMBER_FLOAT:
{
// write double/float
doubleFound(currentState);
currentState = states.SCALAR_FOUND;
// currentPdxList.addDoubleField(jp.getDoubleValue());
setNumberField(jp, currentPdxList);
break;
}
case VALUE_NUMBER_INT:
{
// write int
intFound(currentState);
currentState = states.SCALAR_FOUND;
// currentPdxList.addIntField(jp.getIntValue());
setNumberField(jp, currentPdxList);
break;
}
case VALUE_STRING:
{
// write string
stringFound(currentState);
currentState = states.SCALAR_FOUND;
currentPdxList.addStringField(jp.getText());
currentFieldName = null;
break;
}
case VALUE_TRUE:
{
// write bool
boolFound(currentState);
currentState = states.SCALAR_FOUND;
currentPdxList.addBooleanField(jp.getBooleanValue());
break;
}
default:
{
throw new IllegalStateException("Token not handled in getlist" + nt);
}
}
}
}
use of com.fasterxml.jackson.core.JsonToken in project atlasmap by atlasmap.
the class ActionsJsonDeserializer method processReplaceAllJsonToken.
protected ReplaceAll processReplaceAllJsonToken(JsonParser jsonToken) throws IOException {
ReplaceAll action = new ReplaceAll();
if (JsonToken.END_ARRAY.equals(jsonToken.currentToken()) || JsonToken.END_OBJECT.equals(jsonToken.currentToken())) {
return action;
}
JsonToken nextToken = null;
do {
if (JsonToken.START_OBJECT.equals(jsonToken.currentToken())) {
jsonToken.nextToken();
}
switch(jsonToken.getCurrentName()) {
case ActionsJsonSerializer.MATCH:
jsonToken.nextToken();
action.setMatch(jsonToken.getValueAsString());
break;
case ActionsJsonSerializer.NEW_STRING:
jsonToken.nextToken();
action.setNewString(jsonToken.getValueAsString());
break;
default:
break;
}
nextToken = jsonToken.nextToken();
} while (!JsonToken.END_ARRAY.equals(nextToken) && !JsonToken.END_OBJECT.equals(nextToken));
return action;
}
Aggregations