public static Slice currentTokenAsVarchar ( JsonParser parser ) throws IOException { switch ( parser . currentToken ( ) ) { case VALUE_NULL : return null ; case VALUE_STRING : case FIELD_NAME : return Slices . utf8Slice ( parser . getText ( ) ) ; case VALUE_NUMBER_FLOAT : // Avoidance of loss of precision does not seem to be possible here because of Jackson implementation. return DoubleOperators . castToVarchar ( parser . getDoubleValue ( ) ) ; case VALUE_NUMBER_INT : // An alternative is calling getLongValue and then BigintOperators.castToVarchar. // It doesn't work as well because it can result in overflow and underflow exceptions for large integral numbers. return Slices . utf8Slice ( parser . getText ( ) ) ; case VALUE_TRUE : return BooleanOperators . castToVarchar ( true ) ; case VALUE_FALSE : return BooleanOperators . castToVarchar ( false ) ; default : throw new JsonCastException ( format ( "Unexpected token when cast to %s: %s" , StandardTypes . VARCHAR , parser . getText ( ) ) ) ; } }
utility classes and functions for cast from JSON