Java Code Examples for com.fasterxml.jackson.core.JsonParser.NumberType#LONG

The following examples show how to use com.fasterxml.jackson.core.JsonParser.NumberType#LONG . 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: OptimizedSettableBeanProperty.java    From jackson-modules-base with Apache License 2.0 5 votes vote down vote up
protected final boolean _deserializeBooleanFromOther(JsonParser p, DeserializationContext ctxt)
    throws IOException
{
    if (p.getNumberType() == NumberType.LONG) {
        return (p.getLongValue() == 0L) ? Boolean.FALSE : Boolean.TRUE;
    }
    // no really good logic; let's actually resort to textual comparison
    String str = p.getText();
    if ("0.0".equals(str) || "0".equals(str)) {
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}
 
Example 2
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 3
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;
}