public static Object evaluate ( ReadContext readerContext , String jsonPathExpression ) { String expression = jsonPathExpression ; String jsonPathFunction = null ; for ( String name : JsonPathFunctions . getSupportedFunctions ( ) ) { if ( expression . endsWith ( String . format ( ".%s()" , name ) ) ) { jsonPathFunction = name ; expression = expression . substring ( 0 , expression . length ( ) - String . format ( ".%s()" , name ) . length ( ) ) ; } } Object jsonPathResult = null ; PathNotFoundException pathNotFoundException = null ; try { if ( JsonPath . isPathDefinite ( expression ) ) { jsonPathResult = readerContext . read ( expression ) ; } else { JSONArray values = readerContext . read ( expression ) ; if ( values . size ( ) == 1 ) { jsonPathResult = values . get ( 0 ) ; } else { jsonPathResult = values ; } } } catch ( PathNotFoundException e ) { pathNotFoundException = e ; } if ( StringUtils . hasText ( jsonPathFunction ) ) { jsonPathResult = JsonPathFunctions . evaluate ( jsonPathResult , jsonPathFunction ) ; } if ( jsonPathResult == null && pathNotFoundException != null ) { throw new CitrusRuntimeException ( String . format ( "Failed to evaluate JSON path expression: %s" , jsonPathExpression ) , pathNotFoundException ) ; } return jsonPathResult ; }
Evaluate JsonPath expression using given read context and return result as object .