Java Code Examples for com.fasterxml.jackson.core.JsonToken#VALUE_TRUE

The following examples show how to use com.fasterxml.jackson.core.JsonToken#VALUE_TRUE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonXContentParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Object objectText() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return text();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return text();
    }
}
 
Example 2
Source File: JsonXContentParser.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Object objectText() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return text();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return text();
    }
}
 
Example 3
Source File: BsonParser.java    From immutables with Apache License 2.0 6 votes vote down vote up
@Override
public String getText() throws JsonParseException {
  final JsonToken token = currentToken();
  if (token == JsonToken.FIELD_NAME || type() == null) {
    // return current field name
    return context.fieldName;
  } else if (token == JsonToken.VALUE_NULL || token == JsonToken.VALUE_TRUE || token == JsonToken.VALUE_FALSE) {
    return token.asString();
  }

  if (context.hasValue()) {
    return context.valueAsString();
  }

  readValue();
  return context.valueAsString();
}
 
Example 4
Source File: TableDeserializer.java    From azure-storage-android with Apache License 2.0 6 votes vote down vote up
private static EdmType evaluateEdmType(JsonToken token, String value) {
    EdmType edmType = null;

    if (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE) {
        edmType = EdmType.BOOLEAN;
    }
    else if (token == JsonToken.VALUE_NUMBER_FLOAT) {
        edmType = EdmType.DOUBLE;
    }
    else if (token == JsonToken.VALUE_NUMBER_INT) {
        edmType = EdmType.INT32;
    }
    else {
        edmType = EdmType.STRING;
    }

    return edmType;
}
 
Example 5
Source File: XmlXContentParser.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Override
public Object objectBytes() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return utf8Bytes();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return utf8Bytes();
    }
}
 
Example 6
Source File: XmlXContentParser.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Override
public Object objectText() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return text();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        return text();
    }
}
 
Example 7
Source File: DirectionDeserializer.java    From swagger-inflector with Apache License 2.0 6 votes vote down vote up
@Override
public Set<Configuration.Direction> deserialize(JsonParser jp,
        DeserializationContext ctxt) throws IOException {
    final JsonToken token = jp.getCurrentToken();
    if (token == JsonToken.VALUE_FALSE) {
        return EnumSet.noneOf(Configuration.Direction.class);
    } else if (token == JsonToken.VALUE_TRUE) {
        return EnumSet.allOf(Configuration.Direction.class);
    } else if (token == JsonToken.START_ARRAY) {
        final Set<Configuration.Direction> items = EnumSet.noneOf(Configuration.Direction.class);
        while (true) {
            final JsonToken next = jp.nextToken();
            if (next == JsonToken.VALUE_STRING) {
                final String name = jp.getText();
                items.add(Configuration.Direction.valueOf(name));
            } else if (next == JsonToken.END_ARRAY) {
                return items;
            } else {
                break;
            }
        }
    }
    throw ctxt.mappingException(Configuration.Direction.class);
}
 
Example 8
Source File: JsonldBeanDeserializerModifier.java    From jackson-jsonld with MIT License 6 votes vote down vote up
private Object parseJsonldObject(JsonParser jp) throws IOException {
    Object rval = null;
    final JsonToken initialToken = jp.getCurrentToken();

    if (initialToken == JsonToken.START_ARRAY) {
        jp.setCodec(mapper);
        rval = jp.readValueAs(List.class);
    } else if (initialToken == JsonToken.START_OBJECT) {
        jp.setCodec(mapper);
        rval = jp.readValueAs(Map.class);
    } else if (initialToken == JsonToken.VALUE_STRING) {
        jp.setCodec(mapper);
        rval = jp.readValueAs(String.class);
    } else if (initialToken == JsonToken.VALUE_FALSE || initialToken == JsonToken.VALUE_TRUE) {
        jp.setCodec(mapper);
        rval = jp.readValueAs(Boolean.class);
    } else if (initialToken == JsonToken.VALUE_NUMBER_FLOAT
            || initialToken == JsonToken.VALUE_NUMBER_INT) {
        jp.setCodec(mapper);
        rval = jp.readValueAs(Number.class);
    } else if (initialToken == JsonToken.VALUE_NULL) {
        rval = null;
    }
    return rval;
}
 
Example 9
Source File: JsonXContentParser.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public Object objectBytes() throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_STRING) {
        return utf8Bytes();
    } else if (currentToken == JsonToken.VALUE_NUMBER_INT || currentToken == JsonToken.VALUE_NUMBER_FLOAT) {
        return parser.getNumberValue();
    } else if (currentToken == JsonToken.VALUE_TRUE) {
        return Boolean.TRUE;
    } else if (currentToken == JsonToken.VALUE_FALSE) {
        return Boolean.FALSE;
    } else if (currentToken == JsonToken.VALUE_NULL) {
        return null;
    } else {
        //TODO should this really do UTF-8 conversion?
        return utf8Bytes();
    }
}
 
Example 10
Source File: DocumentParser.java    From vespa with Apache License 2.0 5 votes vote down vote up
private void handleIdentLevelOne(DocumentParseInfo documentParseInfo, boolean docIdAndOperationIsSetExternally)
        throws IOException {
    JsonToken currentToken = parser.getCurrentToken();
    if (currentToken == JsonToken.VALUE_TRUE || currentToken == JsonToken.VALUE_FALSE) {
        try {
            if (CREATE_IF_NON_EXISTENT.equals(parser.getCurrentName())) {
                documentParseInfo.create = Optional.ofNullable(parser.getBooleanValue());
                return;
            }
        } catch (IOException e) {
            throw new RuntimeException("Got IO exception while parsing document", e);
        }
    }
    if ((currentToken == JsonToken.VALUE_TRUE || currentToken == JsonToken.VALUE_FALSE) &&
            CREATE_IF_NON_EXISTENT.equals(parser.getCurrentName())) {
        documentParseInfo.create = Optional.of(currentToken == JsonToken.VALUE_TRUE);
    } else if (currentToken == JsonToken.VALUE_STRING && CONDITION.equals(parser.getCurrentName())) {
        documentParseInfo.condition = Optional.of(parser.getText());
    } else if (currentToken == JsonToken.VALUE_STRING) {
        // Value is expected to be set in the header not in the document. Ignore any unknown field
        // as well.
        if (! docIdAndOperationIsSetExternally) {
            documentParseInfo.operationType = operationNameToOperationType(parser.getCurrentName());
            documentParseInfo.documentId = new DocumentId(parser.getText());
        }
    }
}
 
Example 11
Source File: Session.java    From jlibs with Apache License 2.0 5 votes vote down vote up
private boolean needsAcknowledgement(JsonParser parser) throws IOException{
    boolean acknowledge = false;
    boolean readAcknowledge = false;

    int open = 1;
    while(true){
        JsonToken t = parser.nextToken();
        if(readAcknowledge){
            readAcknowledge = false;
            if(t==JsonToken.VALUE_TRUE)
                acknowledge = true;
            else if(t==JsonToken.VALUE_FALSE)
                acknowledge = false;
        }

        if(t==null)
            throw new JsonParseException("unexpected EOF", parser.getCurrentLocation());
        else if(t.isStructStart())
            open++;
        else if(t.isStructEnd()){
            if(--open==0)
                return acknowledge;
        }else if(open==1 && t==JsonToken.FIELD_NAME && parser.getText().equals("acknowledge")){
            readAcknowledge = true;
        }
    }
}
 
Example 12
Source File: DeserializeJSONJackson.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private cfData	parseArray(JsonParser jp, cfArrayData array, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{
	
	JsonToken	token	= jp.nextToken();
	while ( token != JsonToken.END_ARRAY ){
		
		if ( token == JsonToken.START_ARRAY ){
			array.addElement( parseArray(jp,cfArrayData.createArray(1),bStrictMapping ) );
		}else if ( token == JsonToken.START_OBJECT ){
			array.addElement( parseObject(jp,new cfStructData(),bStrictMapping) );
		}else if ( token == JsonToken.VALUE_NUMBER_INT ){
			
			if ( jp.getNumberType() == NumberType.INT )
				array.addElement( new cfNumberData(jp.getIntValue()) );
			else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER )
				array.addElement( new cfNumberData(jp.getLongValue()) );

		}else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){
	
			if ( jp.getNumberType() == NumberType.FLOAT )
				array.addElement( new cfNumberData(jp.getFloatValue()) );
			else if ( jp.getNumberType() == NumberType.DOUBLE )
				array.addElement( new cfNumberData(jp.getDoubleValue()) );

		} else if ( token == JsonToken.VALUE_FALSE ){
			array.addElement( cfBooleanData.FALSE );
		} else if ( token == JsonToken.VALUE_TRUE ){
			array.addElement( cfBooleanData.TRUE );
		} else if ( token == JsonToken.VALUE_NULL ){
			array.addElement( cfNullData.NULL );
		}else
			array.addElement(  getString(jp.getText()) );
	
		token	= jp.nextToken();
	}
	
	return array;
}
 
Example 13
Source File: WriteHolders.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void write(BitWriter writer, JsonToken token, JsonParser parser) throws IOException {
  // TODO JASON - finish other cases
  if (token == JsonToken.VALUE_NUMBER_INT) {
    writer.writeBit(parser.getIntValue() == 1 ? 1 : 0);
  } else if (token == JsonToken.VALUE_TRUE || token == JsonToken.VALUE_FALSE){
    writer.writeBit(parser.getBooleanValue() ? 1 : 0);
  } else if (token == JsonToken.VALUE_STRING) {
    writer.writeBit(ElasticsearchJsonReader.parseElasticBoolean(parser.getValueAsString()) ? 1 : 0);
  } else {
    throw UserException.dataReadError()
        .message("While reading from elasticsearch, unexpected data type in a boolean column: " + token).build(logger);
  }

}
 
Example 14
Source File: IonParser.java    From ibm-cos-sdk-java with Apache License 2.0 5 votes vote down vote up
private JsonToken getJsonToken() {
    if (reader.isNullValue()) {
        return JsonToken.VALUE_NULL;
    }

    IonType currentType = reader.getType();
    switch (currentType) {
        case BLOB:
        case CLOB:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        case BOOL:
            return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
        case DECIMAL:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case FLOAT:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case INT:
            return JsonToken.VALUE_NUMBER_INT;
        case LIST:
            return JsonToken.START_ARRAY;
        case SEXP:
            return JsonToken.START_ARRAY;
        case STRING:
            return JsonToken.VALUE_STRING;
        case STRUCT:
            return JsonToken.START_OBJECT;
        case SYMBOL:
            return JsonToken.VALUE_STRING;
        case TIMESTAMP:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        default:
            throw new SdkClientException(String.format("Unhandled Ion type %s", currentType));
    }
}
 
Example 15
Source File: IonParser.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
private JsonToken getJsonToken() {
    if (reader.isNullValue()) {
        return JsonToken.VALUE_NULL;
    }

    IonType currentType = reader.getType();
    switch (currentType) {
        case BLOB:
        case CLOB:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        case BOOL:
            return reader.booleanValue() ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
        case DECIMAL:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case FLOAT:
            return JsonToken.VALUE_NUMBER_FLOAT;
        case INT:
            return JsonToken.VALUE_NUMBER_INT;
        case LIST:
            return JsonToken.START_ARRAY;
        case SEXP:
            return JsonToken.START_ARRAY;
        case STRING:
            return JsonToken.VALUE_STRING;
        case STRUCT:
            return JsonToken.START_OBJECT;
        case SYMBOL:
            return JsonToken.VALUE_STRING;
        case TIMESTAMP:
            return JsonToken.VALUE_EMBEDDED_OBJECT;
        default:
            throw SdkClientException.builder()
                                    .message(String.format("Unhandled Ion type %s", currentType))
                                    .build();
    }
}
 
Example 16
Source File: RealmsConfigurationLoader.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static Boolean getBooleanValue(JsonParser p) throws IOException {
    JsonToken t = p.nextToken();
    if (t !=  JsonToken.VALUE_TRUE && t != JsonToken.VALUE_FALSE) {
        throw new RuntimeException("Error while reading field '" + p.getCurrentName() + "'. Expected boolean value [" + t + "]");
    }
    return p.getValueAsBoolean();
}
 
Example 17
Source File: BsonParser.java    From immutables with Apache License 2.0 5 votes vote down vote up
private JsonToken toJsonToken(BsonType type) {
  switch (type) {
    case END_OF_DOCUMENT:
      reader.readEndDocument();
      return JsonToken.END_OBJECT;
    case DOCUMENT:
      reader.readStartDocument();
      return JsonToken.START_OBJECT;
    case ARRAY:
      reader.readStartArray();
      return JsonToken.START_ARRAY;
    case OBJECT_ID:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
    case BOOLEAN:
      final boolean value  = reader.readBoolean();
      return value ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
    case DATE_TIME:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
    case NULL:
      reader.readNull();
      return JsonToken.VALUE_NULL;
    case REGULAR_EXPRESSION:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
    case SYMBOL:
    case STRING:
      return JsonToken.VALUE_STRING;
    case INT32:
    case INT64:
      return JsonToken.VALUE_NUMBER_INT;
    case DECIMAL128:
      return JsonToken.VALUE_NUMBER_FLOAT;
    case DOUBLE:
      return JsonToken.VALUE_NUMBER_FLOAT;
    case BINARY:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
    default:
      throw new IllegalStateException(String.format("Unknown type %s", type));
  }
}
 
Example 18
Source File: DeserializeJSONJackson.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
private cfData	parseObject(JsonParser jp, cfStructData struct, boolean bStrictMapping ) throws JsonParseException, IOException, cfmRunTimeException{
	
	JsonToken	token	= jp.nextToken();
	while ( token != JsonToken.END_OBJECT ){
		String namefield = jp.getCurrentName();
		
		if ( token == JsonToken.START_ARRAY ){
			struct.setData( namefield, parseArray(jp, cfArrayData.createArray(1), bStrictMapping) );
		}else if ( token == JsonToken.START_OBJECT ){
			struct.setData( namefield, parseObject(jp,new cfStructData(), bStrictMapping) );
		}else if ( token == JsonToken.VALUE_NUMBER_INT ){

			if ( jp.getNumberType() == NumberType.INT )
				struct.setData( namefield, new cfNumberData(jp.getIntValue()) );
			else if ( jp.getNumberType() == NumberType.LONG || jp.getNumberType() == NumberType.BIG_INTEGER )
				struct.setData( namefield, new cfNumberData(jp.getLongValue()) );

		}else if ( token == JsonToken.VALUE_NUMBER_FLOAT ){

			if ( jp.getNumberType() == NumberType.FLOAT )
				struct.setData( namefield, new cfNumberData(jp.getFloatValue()) );
			else if ( jp.getNumberType() == NumberType.DOUBLE )
				struct.setData( namefield, new cfNumberData(jp.getDoubleValue()) );

		} else if ( token == JsonToken.VALUE_FALSE ){
			struct.setData( namefield, cfBooleanData.FALSE );
		} else if ( token == JsonToken.VALUE_TRUE ){
			struct.setData( namefield, cfBooleanData.TRUE );
		} else if ( token == JsonToken.VALUE_NULL ){
			struct.setData( namefield, cfNullData.NULL );
		}else{
			struct.setData( namefield, getString(jp.getText()) );
		}

		token	= jp.nextToken();
	}

	if ( bStrictMapping )
		return convertToQuery( struct );
	else
		return struct;
}
 
Example 19
Source File: BsonParser.java    From immutables with Apache License 2.0 4 votes vote down vote up
/**
 * Read next token in the stream
 */
private JsonToken readToken() throws JsonParseException {
  switch (type()) {
    case END_OF_DOCUMENT:
      reader.readEndDocument();
      return JsonToken.END_OBJECT;
    case DOCUMENT:
      reader.readStartDocument();
      return JsonToken.START_OBJECT;
    case ARRAY:
      reader.readStartArray();
      return JsonToken.START_ARRAY;
    case BOOLEAN:
      final boolean value  = reader.readBoolean();
      context.setValue(value);
      return value ? JsonToken.VALUE_TRUE : JsonToken.VALUE_FALSE;
    case DATE_TIME:
    case TIMESTAMP:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
    case NULL:
      reader.readNull();
      context.setValue(null);
      return JsonToken.VALUE_NULL;
    case SYMBOL:
    case STRING:
      return JsonToken.VALUE_STRING;
    case INT32:
    case INT64:
      return JsonToken.VALUE_NUMBER_INT;
    case DECIMAL128:
    case DOUBLE:
      return JsonToken.VALUE_NUMBER_FLOAT;
    case UNDEFINED:
      reader.readUndefined();
      context.setValue(null);
      return JsonToken.VALUE_NULL;
    case OBJECT_ID:
    case BINARY:
    case REGULAR_EXPRESSION:
    default:
      return JsonToken.VALUE_EMBEDDED_OBJECT;
  }
}
 
Example 20
Source File: JsonRecordSupport.java    From syndesis with Apache License 2.0 4 votes vote down vote up
public static void jsonStreamToRecords(Set<String> indexes, JsonParser jp, String path, Consumer<JsonRecord> consumer) throws IOException {
    boolean inArray = false;
    int arrayIndex = 0;
    while (true) {
        JsonToken nextToken = jp.nextToken();

        String currentPath = path;

        if (nextToken == FIELD_NAME) {
            if (inArray) {
                currentPath = path + toArrayIndexPath(arrayIndex) + "/";
            }
            jsonStreamToRecords(indexes, jp, currentPath + validateKey(jp.getCurrentName()) + "/", consumer);
        } else if (nextToken == VALUE_NULL) {
            if (inArray) {
                currentPath = path + toArrayIndexPath(arrayIndex) + "/";
            }
            consumer.accept(JsonRecord.of(currentPath, String.valueOf(NULL_VALUE_PREFIX), "null", indexFieldValue(indexes, currentPath)));
            if( inArray ) {
                arrayIndex++;
            } else {
                return;
            }
        } else if (nextToken.isScalarValue()) {
            if (inArray) {
                currentPath = path + toArrayIndexPath(arrayIndex) + "/";
            }

            String value = jp.getValueAsString();
            String ovalue = null;

            if( nextToken == JsonToken.VALUE_STRING ) {
                value = STRING_VALUE_PREFIX + value; //NOPMD
            } else if( nextToken == JsonToken.VALUE_NUMBER_INT || nextToken == JsonToken.VALUE_NUMBER_FLOAT ) {
                ovalue = value; // hold on to the original number in th ovalue field.
                value = toLexSortableString(value); // encode it so we can lexically sort.
            } else if( nextToken == JsonToken.VALUE_TRUE ) {
                ovalue = value;
                value = String.valueOf(TRUE_VALUE_PREFIX);
            } else if( nextToken == JsonToken.VALUE_FALSE ) {
                ovalue = value;
                value = String.valueOf(FALSE_VALUE_PREFIX);
            }

            consumer.accept(JsonRecord.of(currentPath, value, ovalue, indexFieldValue(indexes, currentPath)));
            if( inArray ) {
                arrayIndex++;
            } else {
                return;
            }
        } else if (nextToken == END_OBJECT) {
            if( inArray ) {
                arrayIndex++;
            } else {
                return;
            }
        } else if (nextToken == START_ARRAY) {
            inArray = true;
        } else if (nextToken == END_ARRAY) {
            return;
        }
    }
}