public java . lang . Object getResultObject ( ApplicationContext applicationContext ) { if ( object == null ) { return null ; } if ( object . getValueObject ( ) != null ) { return object . getValueObject ( ) ; } try { Class argType = Class . forName ( object . getType ( ) ) ; java . lang . Object value = null ; if ( object . getValue ( ) != null ) { value = object . getValue ( ) ; } else if ( StringUtils . hasText ( object . getRef ( ) ) && applicationContext != null ) { value = applicationContext . getBean ( object . getRef ( ) ) ; } if ( value == null ) { return null ; } else if ( argType . isInstance ( value ) || argType . isAssignableFrom ( value . getClass ( ) ) ) { return argType . cast ( value ) ; } else if ( Map . class . equals ( argType ) ) { String mapString = value . toString ( ) ; Properties props = new Properties ( ) ; try { props . load ( new StringReader ( mapString . substring ( 1 , mapString . length ( ) - 1 ) . replace ( ", " , "\n" ) ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to reconstruct service result object of type map" , e ) ; } Map < String , String > map = new LinkedHashMap <> ( ) ; for ( Map . Entry < java . lang . Object , java . lang . Object > entry : props . entrySet ( ) ) { map . put ( entry . getKey ( ) . toString ( ) , entry . getValue ( ) . toString ( ) ) ; } return map ; } else { try { return new SimpleTypeConverter ( ) . convertIfNecessary ( value , argType ) ; } catch ( ConversionNotSupportedException e ) { if ( String . class . equals ( argType ) ) { return value . toString ( ) ; } throw e ; } } } catch ( ClassNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to construct service result object" , e ) ; } }
Gets this service result as object casted to target type if necessary .